fix: add binary check on config reload
This commit is contained in:
parent
3ab9006bdc
commit
ea14f03e1f
1 changed files with 39 additions and 9 deletions
48
src/main.rs
48
src/main.rs
|
@ -219,7 +219,13 @@ async fn main() {
|
||||||
Config::default()
|
Config::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO: add a map to not check for binaries twice?
|
fn check_binary(binary: &str) {
|
||||||
|
if !is_binary_available(binary) {
|
||||||
|
error!("{binary} is not available, exiting.");
|
||||||
|
std::process::exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
match cfg.gamma_backend {
|
match cfg.gamma_backend {
|
||||||
GammaBackend::Hyprctl => check_binary("hyprctl"),
|
GammaBackend::Hyprctl => check_binary("hyprctl"),
|
||||||
GammaBackend::Ddcutil => check_binary("ddcutil"),
|
GammaBackend::Ddcutil => check_binary("ddcutil"),
|
||||||
|
@ -341,9 +347,39 @@ async fn reload_config(notify: Arc<Notify>) {
|
||||||
match Config::load(&config_path) {
|
match Config::load(&config_path) {
|
||||||
Ok(cfg) => {
|
Ok(cfg) => {
|
||||||
debug!("Config file reloaded successfully");
|
debug!("Config file reloaded successfully");
|
||||||
|
|
||||||
|
fn check_binary(binary: &str) -> bool {
|
||||||
|
if !is_binary_available(binary) {
|
||||||
|
error!("{binary} is not available, exiting.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
|
let gamma_check = match cfg.gamma_backend {
|
||||||
|
GammaBackend::Hyprctl => check_binary("hyprctl"),
|
||||||
|
GammaBackend::Ddcutil => check_binary("ddcutil"),
|
||||||
|
GammaBackend::Xsct => check_binary("xsct"),
|
||||||
|
GammaBackend::Redshift => check_binary("redshift"),
|
||||||
|
GammaBackend::Gammastep => check_binary("gammastep"),
|
||||||
|
GammaBackend::None => true,
|
||||||
|
};
|
||||||
|
|
||||||
|
let temp_check = match cfg.temp_backend {
|
||||||
|
TempBackend::Hyprctl => check_binary("hyprctl"),
|
||||||
|
TempBackend::Gammastep => check_binary("gammastep"),
|
||||||
|
TempBackend::Xsct => check_binary("xsct"),
|
||||||
|
TempBackend::Redshift => check_binary("redshift"),
|
||||||
|
TempBackend::None => true,
|
||||||
|
};
|
||||||
|
|
||||||
|
if !gamma_check || !temp_check {
|
||||||
|
error!("One or more binaries are not available, retaining old config.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
*config = cfg;
|
*config = cfg;
|
||||||
reset_cache();
|
reset_cache();
|
||||||
trace!("new config: {:#?}", config);
|
|
||||||
|
|
||||||
let new_modified = std::fs::metadata(&config_path)
|
let new_modified = std::fs::metadata(&config_path)
|
||||||
.and_then(|m| m.modified())
|
.and_then(|m| m.modified())
|
||||||
|
@ -359,6 +395,7 @@ async fn reload_config(notify: Arc<Notify>) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_binary_available(binary_name: &str) -> bool {
|
fn is_binary_available(binary_name: &str) -> bool {
|
||||||
use std::fs;
|
use std::fs;
|
||||||
if let Ok(paths) = env::var("PATH") {
|
if let Ok(paths) = env::var("PATH") {
|
||||||
|
@ -411,10 +448,3 @@ fn config_handle() -> Arc<RwLock<Config>> {
|
||||||
fn get_time() -> Time {
|
fn get_time() -> Time {
|
||||||
Time::now().expect("Failed to get local time")
|
Time::now().expect("Failed to get local time")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_binary(binary: &str) {
|
|
||||||
if !is_binary_available(binary) {
|
|
||||||
error!("{binary} is not available, exiting.");
|
|
||||||
std::process::exit(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue