diff --git a/src/main.rs b/src/main.rs index 2e04d76..daea4e7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -65,6 +65,22 @@ async fn socket_server(disabled: Arc, notify: Arc) { cur_gamma ); } + "reload" => { + trace!("reload dispatched"); + let config_handle = config_handle(); + let mut config = config_handle.write().await; + match Config::load(get_config_path()) { + Ok(cfg) => { + debug!("Config file found, loading..."); + *config = cfg; + notify.notify_one(); + } + Err(err) => { + error!("Failed to load config: {err}"); + warn!("Using default config."); + } + } + } "status_notify" => { trace!("status_notify dispatched"); let now = get_time(); @@ -250,9 +266,9 @@ async fn config_guard() -> tokio::sync::RwLockReadGuard<'static, Config> { CONFIG.get().expect("config not init").read().await } -// fn config_handle() -> Arc> { -// CONFIG.get().expect("config not init").clone() -// } +fn config_handle() -> Arc> { + CONFIG.get().expect("config not init").clone() +} // async fn get_config() -> Config { // let lock = CONFIG.get().expect("config not initialized").read().await;