hyprshell_core_lib/util/
mod.rs

1mod boot;
2mod exec;
3mod helpers;
4mod path;
5
6pub use boot::*;
7pub use exec::*;
8pub use helpers::*;
9pub use path::*;
10use std::env::{var, var_os};
11use std::os::unix::net::UnixStream;
12use std::path::PathBuf;
13use tracing::debug;
14
15#[must_use]
16pub fn get_daemon_socket_path_buff() -> PathBuf {
17    #[allow(clippy::option_if_let_else)]
18    let mut buf = if let Some(runtime_path) = var_os("XDG_RUNTIME_DIR") {
19        if let Some(instance) = var_os("HYPRLAND_INSTANCE_SIGNATURE") {
20            PathBuf::from(runtime_path).join("hypr").join(instance)
21        } else {
22            PathBuf::from(runtime_path)
23        }
24    } else if let Ok(uid) = var("UID") {
25        PathBuf::from("/run/user/".to_owned() + &uid)
26    } else {
27        PathBuf::from("/tmp")
28    };
29    buf.push("hyprshell.sock");
30    buf
31}
32
33pub fn daemon_running() -> bool {
34    // check if socket exists and socket is open
35    let buf = get_daemon_socket_path_buff();
36    if buf.exists() {
37        debug!("Checking if daemon is running on {}", buf.display());
38        UnixStream::connect(buf).is_ok()
39    } else {
40        debug!("Daemon not running");
41        false
42    }
43}