diff --git a/crates/coop/src/dialogs/settings.rs b/crates/coop/src/dialogs/settings.rs index 1e6308a..331e2b7 100644 --- a/crates/coop/src/dialogs/settings.rs +++ b/crates/coop/src/dialogs/settings.rs @@ -4,7 +4,7 @@ use gpui::{ Window, div, px, }; use settings::{AppSettings, AuthMode}; -use theme::{ActiveTheme, ThemeMode}; +use theme::{ActiveTheme, Theme, ThemeMode}; use ui::button::{Button, ButtonVariants}; use ui::group_box::{GroupBox, GroupBoxVariants}; use ui::input::{InputState, TextInput}; @@ -33,6 +33,7 @@ impl Preferences { Self { file_input } } + /// Update the file server (blossom) URL fn update_file_server(&mut self, window: &mut Window, cx: &mut Context) { let value = self.file_input.read(cx).value(); @@ -45,6 +46,12 @@ impl Preferences { } } } + + /// Set the theme mode (light or dark) + fn set_theme_mode(mode: ThemeMode, window: &mut Window, cx: &mut App) { + AppSettings::update_theme_mode(mode, cx); + Theme::change(mode, Some(window), cx); + } } impl Render for Preferences { @@ -160,23 +167,16 @@ impl Render for Preferences { .ghost_alt() .small() .dropdown_menu(|this, _window, _cx| { - this.min_w(px(256.)) - .item(PopupMenuItem::new("Light").on_click( - |_ev, _window, cx| { - AppSettings::update_theme_mode( - ThemeMode::Light, - cx, - ); - }, - )) - .item(PopupMenuItem::new("Dark").on_click( - |_ev, _window, cx| { - AppSettings::update_theme_mode( - ThemeMode::Dark, - cx, - ); - }, - )) + this.item(PopupMenuItem::new("Light").on_click( + |_, window, cx| { + Self::set_theme_mode(ThemeMode::Light, window, cx); + }, + )) + .item( + PopupMenuItem::new("Dark").on_click(|_, window, cx| { + Self::set_theme_mode(ThemeMode::Dark, window, cx); + }), + ) }), ), ) diff --git a/crates/settings/src/lib.rs b/crates/settings/src/lib.rs index 09978dc..d081d31 100644 --- a/crates/settings/src/lib.rs +++ b/crates/settings/src/lib.rs @@ -277,17 +277,6 @@ impl AppSettings { self.apply_theme(window, cx); } - /// Apply theme - pub fn apply_theme(&mut self, window: &mut Window, cx: &mut Context) { - if let Some(name) = self.values.theme.as_ref() { - if let Ok(new_theme) = ThemeFamily::from_assets(name) { - Theme::apply_theme(Rc::new(new_theme), Some(window), cx); - } - } else { - Theme::apply_theme(Rc::new(ThemeFamily::default()), Some(window), cx); - } - } - /// Reset theme pub fn reset_theme(&mut self, window: &mut Window, cx: &mut Context) { self.values.theme = None; @@ -296,6 +285,22 @@ impl AppSettings { self.apply_theme(window, cx); } + /// Apply theme + pub fn apply_theme(&mut self, window: &mut Window, cx: &mut Context) { + if let Some(name) = self.values.theme.as_ref() { + let mode = self.values.theme_mode; + + if let Ok(new_theme) = ThemeFamily::from_assets(name) { + Theme::apply_theme(Rc::new(new_theme), Some(window), cx); + Theme::change(mode, Some(window), cx); + } else { + log::info!("Failed to load theme: {name}"); + } + } else { + Theme::apply_theme(Rc::new(ThemeFamily::default()), Some(window), cx); + } + } + /// Check if the given relay is already authenticated pub fn trusted_relay(&self, url: &RelayUrl, _cx: &App) -> bool { self.values.trusted_relays.iter().any(|relay| {