hyprshell_core_lib/util/
mod.rs

1mod r#const;
2mod exec;
3mod helpers;
4mod version;
5
6pub use r#const::*;
7pub use exec::*;
8pub use helpers::*;
9pub use version::*;
10
11pub fn get_daemon_socket_path_buff() -> std::path::PathBuf {
12    let mut buf = if let Some(runtime_path) = std::env::var_os("XDG_RUNTIME_DIR") {
13        std::path::PathBuf::from(runtime_path)
14    } else if let Ok(uid) = std::env::var("UID") {
15        std::path::PathBuf::from("/run/user/".to_owned() + &uid)
16    } else {
17        std::path::PathBuf::from("/tmp")
18    };
19    buf.push("hyprshell.sock");
20    buf
21}
22
23pub fn daemon_running() -> bool {
24    // check if socket exists and socket is open
25    let buf = get_daemon_socket_path_buff();
26    if buf.exists() {
27        tracing::debug!("Checking if daemon is running");
28        std::os::unix::net::UnixStream::connect(buf).is_ok()
29    } else {
30        tracing::debug!("Daemon not running");
31        false
32    }
33}