Skip to main content

hyprshell_core_lib/util/
mod.rs

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