hyprshell_core_lib/util/
mod.rs1mod r#const;
2mod exec;
3mod helpers;
4mod path;
5
6pub use r#const::*;
7pub use exec::*;
8pub use helpers::*;
9pub use path::*;
10use std::env::{var, var_os};
11use std::path::Path;
12
13#[must_use]
14pub fn get_daemon_socket_path_buff() -> std::path::PathBuf {
15 #[allow(clippy::option_if_let_else)]
16 let mut buf = if let Some(runtime_path) = var_os("XDG_RUNTIME_DIR") {
17 if let Some(instance) = var_os("HYPRLAND_INSTANCE_SIGNATURE") {
18 std::path::PathBuf::from(runtime_path)
19 .join("hypr")
20 .join(instance)
21 } else {
22 std::path::PathBuf::from(runtime_path)
23 }
24 } else if let Ok(uid) = var("UID") {
25 std::path::PathBuf::from("/run/user/".to_owned() + &uid)
26 } else {
27 std::path::PathBuf::from("/tmp")
28 };
29 buf.push("hyprshell.sock");
30 buf
31}
32
33pub fn daemon_running() -> bool {
34 let buf = get_daemon_socket_path_buff();
36 if buf.exists() {
37 tracing::debug!("Checking if daemon is running");
38 std::os::unix::net::UnixStream::connect(buf).is_ok()
39 } else {
40 tracing::debug!("Daemon not running");
41 false
42 }
43}
44
45#[allow(clippy::print_stderr, clippy::print_stdout)]
46pub fn explain_config(config_path: &Path) {
47 let config = match config_lib::load_and_migrate_config(config_path, true) {
48 Ok(config) => config,
49 Err(err) => {
50 eprintln!(
51 "\x1b[1m\x1b[31mConfig is invalid ({}):\x1b[0m {err:?}\n",
52 config_path.display()
53 );
54 return;
55 }
56 };
57 let info = config_lib::explain(&config, config_path, true);
58 println!("{info}");
59
60 if daemon_running() {
61 println!("Daemon \x1b[32mrunning\x1b[0m");
62 } else {
63 eprintln!(
64 "Daemon \x1b[31mnot running\x1b[0m, start it with `hyprshell run` or `systemctl --user enable --now hyprshell`"
65 );
66 }
67}