feat: explode if no hyprctl

This commit is contained in:
Vladimir Rubin 2025-04-26 20:08:47 +03:00
parent 2a3ec6df03
commit 6063f5cb0a
Signed by: vavakado
GPG key ID: CAB744727F36B524

View file

@ -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<RwLock<Config>> {
// CONFIG.get().expect("config not init").clone()
// }