diff options
| author | Ogulcan Celik <ogulcancelik@gmail.com> | 2026-03-29 22:48:02 +0300 |
|---|---|---|
| committer | Ogulcan Celik <ogulcancelik@gmail.com> | 2026-03-29 22:48:02 +0300 |
| commit | 9badd642b7c0c71301cb5034245706f700401ba0 (patch) | |
| tree | c598ece50568519387e7c7eb92d3a79edaf37b47 /src/app/mod.rs | |
| parent | 101de0ce453615c809d95175532bcb86f816163a (diff) | |
fix popup rendering and settings theme flow
Diffstat (limited to 'src/app/mod.rs')
| -rw-r--r-- | src/app/mod.rs | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/app/mod.rs b/src/app/mod.rs index 6562c5d6..e1f371ab 100644 --- a/src/app/mod.rs +++ b/src/app/mod.rs @@ -140,6 +140,17 @@ impl App { keybinds: config.keybinds(), spinner_tick: 0, palette: resolve_palette(&config), + theme_name: config + .theme + .name + .clone() + .unwrap_or_else(|| "catppuccin".to_string()), + settings: state::SettingsState { + section: state::SettingsSection::Theme, + selected: 0, + original_palette: None, + original_theme: None, + }, }; // Background auto-update (skipped in --no-session / test mode) @@ -902,6 +913,46 @@ impl App { } } + fn update_config_file<F>(&mut self, error_context: &str, update: F) + where + F: FnOnce(&str) -> String, + { + let path = crate::config::config_path(); + if let Some(parent) = path.parent() { + if let Err(err) = std::fs::create_dir_all(parent) { + self.state.config_diagnostic = + Some(format!("failed to save {error_context}: {err}")); + self.config_diagnostic_deadline = Some(Instant::now() + Duration::from_secs(5)); + return; + } + } + + let content = std::fs::read_to_string(&path).unwrap_or_default(); + let new_content = update(&content); + if let Err(err) = std::fs::write(&path, new_content) { + self.state.config_diagnostic = Some(format!("failed to save {error_context}: {err}")); + self.config_diagnostic_deadline = Some(Instant::now() + Duration::from_secs(5)); + } + } + + fn save_theme(&mut self, name: &str) { + self.update_config_file("theme", |content| { + crate::config::upsert_section_value(content, "theme", "name", &format!("\"{name}\"")) + }); + } + + fn save_sound(&mut self, enabled: bool) { + self.update_config_file("sound setting", |content| { + crate::config::upsert_section_bool(content, "ui.sound", "enabled", enabled) + }); + } + + fn save_toast(&mut self, enabled: bool) { + self.update_config_file("toast setting", |content| { + crate::config::upsert_section_bool(content, "ui.toast", "enabled", enabled) + }); + } + /// Create a workspace with a real PTY (needs event_tx). fn create_workspace(&mut self) { let initial_cwd = self |
