chore: fix issue where setting theme mode doesn't work

This commit is contained in:
Ren Amamiya
2026-03-31 08:13:10 +07:00
parent 8205c69e19
commit c8034642c5
2 changed files with 34 additions and 29 deletions

View File

@@ -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<Self>) {
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);
}),
)
}),
),
)

View File

@@ -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<Self>) {
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>) {
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<Self>) {
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| {