theme: Simplify init (#237)

This commit is contained in:
Floyd Wang 2024-09-12 16:14:41 +08:00 committed by GitHub
parent cf551654fe
commit 9388b88f59
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 8 additions and 12 deletions

View file

@ -31,7 +31,6 @@ actions!(workspace, [Open, CloseWindow]);
pub fn init(_app_state: Arc<AppState>, cx: &mut AppContext) {
cx.on_action(|_action: &Open, _cx: &mut AppContext| {});
Theme::init(cx);
ui::init(cx);
story::init(cx);
}

View file

@ -58,6 +58,7 @@ pub use svg_img::*;
/// Initialize the UI module.
pub fn init(cx: &mut gpui::AppContext) {
theme::init(cx);
context_menu::init(cx);
date_picker::init(cx);
dock::init(cx);

View file

@ -5,6 +5,10 @@ use gpui::{
ViewContext, WindowAppearance, WindowContext,
};
pub fn init(cx: &mut AppContext) {
Theme::sync_system_appearance(cx)
}
pub trait ActiveTheme {
fn theme(&self) -> &Theme;
}
@ -328,7 +332,7 @@ impl Theme {
impl From<Colors> for Theme {
fn from(colors: Colors) -> Self {
Theme {
mode: ThemeMode::Dark,
mode: ThemeMode::default(),
transparent: Hsla::transparent_black(),
font_size: 14.0,
font_family: if cfg!(target_os = "macos") {
@ -397,9 +401,10 @@ impl From<Colors> for Theme {
}
}
#[derive(Debug, PartialEq, PartialOrd, Eq)]
#[derive(Debug, Default, PartialEq, PartialOrd, Eq)]
pub enum ThemeMode {
Light,
#[default]
Dark,
}
@ -410,15 +415,6 @@ impl ThemeMode {
}
impl Theme {
fn new() -> Self {
Self::from(Colors::dark())
}
pub fn init(cx: &mut AppContext) {
cx.set_global(Theme::new());
Self::sync_system_appearance(cx)
}
/// Sync the theme with the system appearance
pub fn sync_system_appearance(cx: &mut AppContext) {
match cx.window_appearance() {