diff options
| author | Ogulcan Celik <ogulcancelik@gmail.com> | 2026-04-26 02:07:33 +0300 |
|---|---|---|
| committer | Ogulcan Celik <ogulcancelik@gmail.com> | 2026-04-26 02:07:33 +0300 |
| commit | 3d1ef155bf9846f39725bf22c54666da2bc42330 (patch) | |
| tree | f4b4c3eca6c6f821dbfe86bcee0fd6a5d9ab9da9 /src/config/io.rs | |
| parent | ef4182efd9f15e6c13d91d45e525b094cdcee2fe (diff) | |
feat: add live config reload
Diffstat (limited to 'src/config/io.rs')
| -rw-r--r-- | src/config/io.rs | 42 |
1 files changed, 28 insertions, 14 deletions
diff --git a/src/config/io.rs b/src/config/io.rs index 1a3c1920..2774fc93 100644 --- a/src/config/io.rs +++ b/src/config/io.rs @@ -2,7 +2,7 @@ use std::path::{Path, PathBuf}; use tracing::warn; -use super::{model::LoadedConfig, Config, LiveKeybindConfig, CONFIG_PATH_ENV_VAR}; +use super::{model::LoadedConfig, Config, CONFIG_PATH_ENV_VAR}; pub fn app_dir_name() -> &'static str { if cfg!(debug_assertions) { @@ -77,23 +77,37 @@ pub fn config_path() -> PathBuf { config_dir().join("config.toml") } -pub fn load_live_keybinds() -> Result<LiveKeybindConfig, Vec<String>> { +pub fn config_diagnostic_summary(diagnostics: &[String]) -> Option<String> { + if diagnostics.is_empty() { + None + } else if diagnostics.len() == 1 { + Some(diagnostics[0].clone()) + } else { + Some(format!( + "{} (and {} more)", + diagnostics[0], + diagnostics.len() - 1 + )) + } +} + +pub fn load_live_config() -> Result<LoadedConfig, Vec<String>> { let path = config_path(); if !path.exists() { - return Config::default().live_keybinds(); + return Ok(LoadedConfig { + config: Config::default(), + diagnostics: Vec::new(), + }); } - let content = std::fs::read_to_string(&path).map_err(|err| { - vec![format!( - "config read error: {err}; keeping current keybinds" - )] - })?; - let config = toml::from_str::<Config>(&content).map_err(|err| { - vec![format!( - "config parse error: {err}; keeping current keybinds" - )] - })?; - config.live_keybinds() + let content = std::fs::read_to_string(&path) + .map_err(|err| vec![format!("config read error: {err}; keeping current config")])?; + let config = toml::from_str::<Config>(&content) + .map_err(|err| vec![format!("config parse error: {err}; keeping current config")])?; + Ok(LoadedConfig { + config, + diagnostics: Vec::new(), + }) } pub(crate) fn upsert_top_level_bool(content: &str, key: &str, value: bool) -> String { |
