feat: watch linux theme changed (#7781)

* feat: add Linux theme change notifications and update dark-light dependency

* fix: remove unused tauri Emitter import

* update changelog

* fix: clippy

* fix: pnpm format
This commit is contained in:
oomeow
2026-08-20 16:09:16 +00:00
committed by GitHub
parent 332097bc9f
commit e71cf0ec68
6 changed files with 97 additions and 40 deletions
+25 -6
View File
@@ -16,13 +16,30 @@ pub enum FrontendEvent<'a> {
RefreshVerge,
RefreshProfiles,
RefreshProxyConfig,
NoticeMessage { status: &'a str, message: String },
ProfileChanged { current_profile_id: &'a String },
TimerUpdated { profile_index: &'a String },
ProfileUpdateStarted { uid: &'a String },
ProfileUpdateCompleted { uid: &'a String },
RunStateChanged { state: serde_json::Value },
NoticeMessage {
status: &'a str,
message: String,
},
ProfileChanged {
current_profile_id: &'a String,
},
TimerUpdated {
profile_index: &'a String,
},
ProfileUpdateStarted {
uid: &'a String,
},
ProfileUpdateCompleted {
uid: &'a String,
},
RunStateChanged {
state: serde_json::Value,
},
PendingFailuresChanged,
#[cfg(target_os = "linux")]
ThemeChanged {
theme: tauri::Theme,
},
}
/// Operation associated with a pending failure.
@@ -279,6 +296,8 @@ impl NotificationSystem {
FrontendEvent::ProfileUpdateCompleted { uid } => ("profile-update-completed", Ok(json!({ "uid": uid }))),
FrontendEvent::RunStateChanged { state } => ("verge://run-state-changed", Ok(state)),
FrontendEvent::PendingFailuresChanged => ("verge://pending-failures-changed", Ok(serde_json::Value::Null)),
#[cfg(target_os = "linux")]
FrontendEvent::ThemeChanged { theme } => ("tauri://theme-changed", serde_json::to_value(theme)),
}
}
+26
View File
@@ -40,6 +40,8 @@ pub fn resolve_setup_sync() {
AsyncHandler::spawn(|| async {
AsyncHandler::spawn_blocking(init_scheme);
AsyncHandler::spawn_blocking(init_embed_server);
#[cfg(target_os = "linux")]
AsyncHandler::spawn_blocking(watch_linux_theme_changed);
});
}
@@ -111,6 +113,30 @@ pub(super) fn init_embed_server() {
server::embed_server();
}
#[cfg(target_os = "linux")]
pub(crate) fn watch_linux_theme_changed() {
match dark_light::subscribe() {
Ok(watcher) => {
for mode in watcher.iter() {
use crate::core::notification;
let theme = match mode {
dark_light::Mode::Light => tauri::Theme::Light,
dark_light::Mode::Dark => tauri::Theme::Dark,
dark_light::Mode::Unspecified => tauri::Theme::Light, // fallback to light
};
notification::NotificationSystem::send_event(
Handle::app_handle().clone(),
notification::FrontendEvent::ThemeChanged { theme },
);
}
}
Err(e) => {
logging_error!(Type::Setup, "Fail to watch linux theme changed: {}", e);
}
}
}
pub(super) async fn init_resources() {
logging_error!(Type::Setup, init::init_resources().await);
}