From 6063f5cb0a9c22e644cbe3775c2a7bbf673edffd Mon Sep 17 00:00:00 2001 From: Vladimir Rubin Date: Sat, 26 Apr 2025 20:08:47 +0300 Subject: [PATCH] feat: explode if no hyprctl --- src/main.rs | 39 ++++++++++++++++++--------------------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/src/main.rs b/src/main.rs index af96215..06badfc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -103,6 +103,11 @@ async fn main() { env_logger::init(); log::info!("starting the daemon"); + if !is_binary_available("hyprctl") { + error!("hyprctl is not available, exiting."); + std::process::exit(1); + } + let disabled = Arc::new(AtomicBool::new(false)); let notify = Arc::new(Notify::new()); @@ -193,6 +198,19 @@ async fn main() { } } +fn is_binary_available(binary_name: &str) -> bool { + use std::fs; + if let Ok(paths) = env::var("PATH") { + for path in env::split_paths(&paths) { + let full_path = path.join(binary_name); + if full_path.exists() && fs::metadata(&full_path).map(|m| m.is_file()).unwrap_or(false) { + return true; + } + } + } + false +} + #[inline] fn get_config_path() -> PathBuf { if cfg!(target_os = "windows") { @@ -216,27 +234,6 @@ async fn config_guard() -> tokio::sync::RwLockReadGuard<'static, Config> { CONFIG.get().expect("config not init").read().await } - -fn is_binary_available(binary_name: &str) -> bool { - if let Ok(paths) = env::var("PATH") { - for path in env::split_paths(&paths) { - let full_path = path.join(binary_name); - if full_path.exists() && fs::metadata(&full_path).map(|m| m.is_file()).unwrap_or(false) { - return true; - } - // On Windows, check with .exe extension - #[cfg(windows)] - { - let full_path_exe = path.join(format!("{}.exe", binary_name)); - if full_path_exe.exists() && fs::metadata(&full_path_exe).map(|m| m.is_file()).unwrap_or(false) { - return true; - } - } - } - } - false -} - // fn config_handle() -> Arc> { // CONFIG.get().expect("config not init").clone() // }