Apply OS theme via native-theme on desktop

This commit is contained in:
2026-10-21 21:09:00 +07:00
parent 6117c8184c
commit cab58f6332
7 changed files with 413 additions and 31 deletions
+18
View File
@@ -35,6 +35,24 @@ pub fn init(cx: &mut App) {
AppSettings::set_global(cx.new(AppSettings::new), cx)
}
/// Read the persisted appearance mode synchronously.
///
/// The async load fills the global settings later; the native theme must be
/// applied before the first window opens, so boot reads the mode straight
/// from the settings file instead.
pub fn persisted_appearance_mode() -> AppearanceMode {
#[cfg(not(target_arch = "wasm32"))]
{
let path = config_dir().join(".settings");
if let Ok(content) = std::fs::read_to_string(path)
&& let Ok(settings) = serde_json::from_str::<Settings>(&content)
{
return settings.appearance_mode;
}
}
AppearanceMode::default()
}
const DEFAULT_FILE_SERVER: &str = "https://nostr.download/";
const LEGACY_FILE_SERVER: &str = "blossom.band";
+8 -5
View File
@@ -88,12 +88,15 @@ impl Workspace {
let workspace = cx.entity().downgrade();
let mut subscriptions = smallvec![];
subscriptions.push(
// Observe system appearance and update theme
cx.observe_window_appearance(window, |_this, window, cx| {
// Follow OS appearance changes only when the user has not pinned a
// mode; the native-theme watcher drives runtime changes either way.
// The `::settings` path is the external crate; the crate-local
// `settings` module is the preferences dialog.
if ::settings::AppSettings::get_appearance_mode(cx) == ::settings::AppearanceMode::System {
subscriptions.push(cx.observe_window_appearance(window, |_this, window, cx| {
gpui_kit::component::Theme::sync_system_appearance(Some(window), cx);
}),
);
}));
}
subscriptions.push(
// Subscribe to the nostr events