diff options
Diffstat (limited to 'src/app/config_io.rs')
| -rw-r--r-- | src/app/config_io.rs | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/src/app/config_io.rs b/src/app/config_io.rs index 6770d61e..6c51ad9f 100644 --- a/src/app/config_io.rs +++ b/src/app/config_io.rs @@ -1,7 +1,7 @@ use super::App; impl App { - pub(super) fn update_config_file<F>(&mut self, error_context: &str, update: F) + pub(super) fn update_config_file<F>(&mut self, error_context: &str, update: F) -> bool where F: FnOnce(&str) -> String, { @@ -13,7 +13,7 @@ impl App { Some(format!("failed to save {error_context}: {err}")); self.config_diagnostic_deadline = Some(std::time::Instant::now() + std::time::Duration::from_secs(5)); - return; + return false; } } @@ -24,7 +24,10 @@ impl App { self.state.config_diagnostic = Some(format!("failed to save {error_context}: {err}")); self.config_diagnostic_deadline = Some(std::time::Instant::now() + std::time::Duration::from_secs(5)); + return false; } + + true } pub(super) fn mark_onboarding_complete(&mut self) { @@ -34,15 +37,19 @@ impl App { } pub(super) fn save_theme(&mut self, name: &str) { - self.update_config_file("theme", |content| { + if self.update_config_file("theme", |content| { crate::config::upsert_section_value(content, "theme", "name", &format!("\"{name}\"")) - }); + }) { + self.apply_config_from_disk(false); + } } pub(super) fn save_sound(&mut self, enabled: bool) { - self.update_config_file("sound setting", |content| { + if self.update_config_file("sound setting", |content| { crate::config::upsert_section_bool(content, "ui.sound", "enabled", enabled) - }); + }) { + self.apply_config_from_disk(false); + } } pub(super) fn save_toast_delivery(&mut self, delivery: crate::config::ToastDelivery) { @@ -51,10 +58,12 @@ impl App { crate::config::ToastDelivery::Herdr => "\"herdr\"", crate::config::ToastDelivery::Terminal => "\"terminal\"", }; - self.update_config_file("toast setting", |content| { + if self.update_config_file("toast setting", |content| { let content = crate::config::upsert_section_value(content, "ui.toast", "delivery", value); crate::config::remove_section_key(&content, "ui.toast", "enabled") - }); + }) { + self.apply_config_from_disk(false); + } } } |
