Follow the OS native theme on macOS, Windows and Linux
This commit is contained in:
+37
-31
@@ -5,6 +5,7 @@ use dock::TAB_BAR_HEIGHT;
|
||||
use gpui::*;
|
||||
use gpui_component::{Theme, ThemeMode, ThemeRegistry, theme};
|
||||
use gpui_platform::application;
|
||||
use native_theme_gpui::{SystemTheme, apply_system_theme};
|
||||
use settings::{AppearanceMode, SettingsStore};
|
||||
|
||||
actions!(signed, [Quit]);
|
||||
@@ -25,47 +26,51 @@ fn main() {
|
||||
// The persisted settings must load before the theme is applied.
|
||||
let store = cx.new(|cx| SettingsStore::new(paths::settings_file(), cx));
|
||||
SettingsStore::set_global(store.clone(), cx);
|
||||
let settings = store.read(cx).settings().clone();
|
||||
|
||||
let settings = store.read(cx).settings().clone();
|
||||
let registry = ThemeRegistry::global_mut(cx);
|
||||
|
||||
for (name, content) in Assets.themes() {
|
||||
if let Err(err) = registry.load_themes_from_str(&content) {
|
||||
tracing::error!("Failed to load theme {name}: {err}");
|
||||
}
|
||||
}
|
||||
let light_theme = registry
|
||||
.themes()
|
||||
.get(settings.theme.light_theme.as_str())
|
||||
.cloned();
|
||||
let dark_theme = registry
|
||||
.themes()
|
||||
.get(settings.theme.dark_theme.as_str())
|
||||
.cloned();
|
||||
|
||||
let theme = Theme::global_mut(cx);
|
||||
theme.radius = px(settings.theme.radius);
|
||||
theme.radius_lg = px(settings.theme.radius_lg);
|
||||
theme.focus_ring = settings.theme.focus_ring;
|
||||
theme.shadow = settings.theme.shadow;
|
||||
theme.font_size = px(settings.theme.font_size);
|
||||
theme.mono_font_size = px(settings.theme.mono_font_size);
|
||||
match SystemTheme::from_system() {
|
||||
Ok(system) => apply_system_theme(&system, cx),
|
||||
Err(error) => {
|
||||
tracing::warn!("native theme unavailable ({error})");
|
||||
|
||||
if let Some(light) = light_theme {
|
||||
theme.light_theme = light;
|
||||
} else {
|
||||
tracing::warn!(
|
||||
"{} theme is missing from the registry",
|
||||
settings.theme.light_theme
|
||||
);
|
||||
}
|
||||
let light_theme = registry
|
||||
.themes()
|
||||
.get(settings.theme.light_theme.as_str())
|
||||
.cloned();
|
||||
|
||||
if let Some(dark) = dark_theme {
|
||||
theme.dark_theme = dark;
|
||||
} else {
|
||||
tracing::warn!(
|
||||
"{} theme is missing from the registry",
|
||||
settings.theme.dark_theme
|
||||
);
|
||||
let dark_theme = registry
|
||||
.themes()
|
||||
.get(settings.theme.dark_theme.as_str())
|
||||
.cloned();
|
||||
|
||||
let theme = Theme::global_mut(cx);
|
||||
theme.radius = px(settings.theme.radius);
|
||||
theme.radius_lg = px(settings.theme.radius_lg);
|
||||
theme.focus_ring = settings.theme.focus_ring;
|
||||
theme.shadow = settings.theme.shadow;
|
||||
theme.font_size = px(settings.theme.font_size);
|
||||
theme.mono_font_size = px(settings.theme.mono_font_size);
|
||||
|
||||
if let Some(light) = light_theme {
|
||||
theme.light_theme = light;
|
||||
} else {
|
||||
tracing::warn!("{} theme is missing", settings.theme.light_theme);
|
||||
}
|
||||
|
||||
if let Some(dark) = dark_theme {
|
||||
theme.dark_theme = dark;
|
||||
} else {
|
||||
tracing::warn!("{} theme is missing", settings.theme.dark_theme);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
match settings.appearance {
|
||||
@@ -76,6 +81,7 @@ fn main() {
|
||||
|
||||
std::fs::create_dir_all(paths::nostr_dir()).ok();
|
||||
std::fs::create_dir_all(paths::repos_dir()).ok();
|
||||
|
||||
signed_state::init(
|
||||
paths::nostr_dir(),
|
||||
paths::repos_dir().clone(),
|
||||
|
||||
Reference in New Issue
Block a user