Sync with system appearance.
This commit is contained in:
parent
3e8421c495
commit
a3c14e1515
3 changed files with 20 additions and 3 deletions
|
|
@ -4,7 +4,6 @@ use gpui::{
|
||||||
RenderOnce, SharedString, StyleRefinement, Styled, Svg, TextStyle, TextStyleRefinement,
|
RenderOnce, SharedString, StyleRefinement, Styled, Svg, TextStyle, TextStyleRefinement,
|
||||||
WindowContext,
|
WindowContext,
|
||||||
};
|
};
|
||||||
use windows::Win32::Foundation::NOERROR;
|
|
||||||
|
|
||||||
#[derive(IntoElement)]
|
#[derive(IntoElement)]
|
||||||
pub enum IconName {
|
pub enum IconName {
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use gpui::{hsla, AppContext, Global, Hsla};
|
use gpui::{hsla, AppContext, Global, Hsla, WindowAppearance};
|
||||||
|
|
||||||
pub trait ActiveTheme {
|
pub trait ActiveTheme {
|
||||||
fn theme(&self) -> &Theme;
|
fn theme(&self) -> &Theme;
|
||||||
|
|
@ -293,7 +293,20 @@ impl Theme {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn init(cx: &mut AppContext) {
|
pub fn init(cx: &mut AppContext) {
|
||||||
cx.set_global(Theme::new())
|
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() {
|
||||||
|
WindowAppearance::Dark | WindowAppearance::VibrantDark => {
|
||||||
|
Self::change(ThemeMode::Dark, cx)
|
||||||
|
}
|
||||||
|
WindowAppearance::Light | WindowAppearance::VibrantLight => {
|
||||||
|
Self::change(ThemeMode::Light, cx)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn change(mode: ThemeMode, cx: &mut AppContext) {
|
pub fn change(mode: ThemeMode, cx: &mut AppContext) {
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,11 @@ impl Workspace {
|
||||||
_parent: Option<WeakView<Self>>,
|
_parent: Option<WeakView<Self>>,
|
||||||
cx: &mut ViewContext<Self>,
|
cx: &mut ViewContext<Self>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
|
cx.observe_window_appearance(|_workspace, cx| {
|
||||||
|
Theme::sync_system_appearance(cx);
|
||||||
|
})
|
||||||
|
.detach();
|
||||||
|
|
||||||
Workspace {
|
Workspace {
|
||||||
stories: Stories::view(cx),
|
stories: Stories::view(cx),
|
||||||
notifications: Default::default(),
|
notifications: Default::default(),
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue