chore: fix issue where setting theme mode doesn't work
This commit is contained in:
@@ -4,7 +4,7 @@ use gpui::{
|
|||||||
Window, div, px,
|
Window, div, px,
|
||||||
};
|
};
|
||||||
use settings::{AppSettings, AuthMode};
|
use settings::{AppSettings, AuthMode};
|
||||||
use theme::{ActiveTheme, ThemeMode};
|
use theme::{ActiveTheme, Theme, ThemeMode};
|
||||||
use ui::button::{Button, ButtonVariants};
|
use ui::button::{Button, ButtonVariants};
|
||||||
use ui::group_box::{GroupBox, GroupBoxVariants};
|
use ui::group_box::{GroupBox, GroupBoxVariants};
|
||||||
use ui::input::{InputState, TextInput};
|
use ui::input::{InputState, TextInput};
|
||||||
@@ -33,6 +33,7 @@ impl Preferences {
|
|||||||
Self { file_input }
|
Self { file_input }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Update the file server (blossom) URL
|
||||||
fn update_file_server(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
fn update_file_server(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
||||||
let value = self.file_input.read(cx).value();
|
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 {
|
impl Render for Preferences {
|
||||||
@@ -160,23 +167,16 @@ impl Render for Preferences {
|
|||||||
.ghost_alt()
|
.ghost_alt()
|
||||||
.small()
|
.small()
|
||||||
.dropdown_menu(|this, _window, _cx| {
|
.dropdown_menu(|this, _window, _cx| {
|
||||||
this.min_w(px(256.))
|
this.item(PopupMenuItem::new("Light").on_click(
|
||||||
.item(PopupMenuItem::new("Light").on_click(
|
|_, window, cx| {
|
||||||
|_ev, _window, cx| {
|
Self::set_theme_mode(ThemeMode::Light, 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,
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
))
|
))
|
||||||
|
.item(
|
||||||
|
PopupMenuItem::new("Dark").on_click(|_, window, cx| {
|
||||||
|
Self::set_theme_mode(ThemeMode::Dark, window, cx);
|
||||||
|
}),
|
||||||
|
)
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -277,17 +277,6 @@ impl AppSettings {
|
|||||||
self.apply_theme(window, cx);
|
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
|
/// Reset theme
|
||||||
pub fn reset_theme(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
pub fn reset_theme(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
||||||
self.values.theme = None;
|
self.values.theme = None;
|
||||||
@@ -296,6 +285,22 @@ impl AppSettings {
|
|||||||
self.apply_theme(window, cx);
|
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
|
/// Check if the given relay is already authenticated
|
||||||
pub fn trusted_relay(&self, url: &RelayUrl, _cx: &App) -> bool {
|
pub fn trusted_relay(&self, url: &RelayUrl, _cx: &App) -> bool {
|
||||||
self.values.trusted_relays.iter().any(|relay| {
|
self.values.trusted_relays.iter().any(|relay| {
|
||||||
|
|||||||
Reference in New Issue
Block a user