feat: explode if no hyprctl
This commit is contained in:
parent
2a3ec6df03
commit
6063f5cb0a
1 changed files with 18 additions and 21 deletions
39
src/main.rs
39
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<RwLock<Config>> {
|
||||
// CONFIG.get().expect("config not init").clone()
|
||||
// }
|
||||
|
|
Loading…
Reference in a new issue