From e71cf0ec68133fc90b9751c73aae0dcd65c83f7f Mon Sep 17 00:00:00 2001 From: oomeow Date: Thu, 20 Aug 2026 16:09:16 +0000 Subject: [PATCH] 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 --- Cargo.lock | 71 ++++++++++++++++++------------ Changelog.md | 1 + scripts/dev-service.mjs | 5 +-- src-tauri/Cargo.toml | 3 +- src-tauri/src/core/notification.rs | 31 ++++++++++--- src-tauri/src/utils/resolve/mod.rs | 26 +++++++++++ 6 files changed, 97 insertions(+), 40 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5bbca851c..ad9fa8e11 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1777,13 +1777,18 @@ dependencies = [ [[package]] name = "dark-light" -version = "2.0.0" -source = "git+https://github.com/rust-dark-light/dark-light#0f18d2fbcaa5d1c175db8aae7d53428988d7e961" +version = "3.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f66b71ac6b73812b0bf51cda8dd646a268fbb38623f45b2b7907593c323f745" dependencies = [ + "futures-channel", + "futures-core", "objc2", "objc2-foundation", + "wasm-bindgen", "web-sys", - "winreg 0.55.0", + "windows-sys 0.61.2", + "winreg 0.56.0", "zbus", ] @@ -2044,7 +2049,7 @@ dependencies = [ "libc", "option-ext", "redox_users 0.5.2", - "windows-sys 0.61.2", + "windows-sys 0.60.2", ] [[package]] @@ -2318,7 +2323,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" dependencies = [ "libc", - "windows-sys 0.61.2", + "windows-sys 0.52.0", ] [[package]] @@ -4388,7 +4393,7 @@ version = "0.50.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7957b9740744892f114936ab4a57b3f487491bbeafaf8083688b16841a4240e5" dependencies = [ - "windows-sys 0.61.2", + "windows-sys 0.60.2", ] [[package]] @@ -4453,7 +4458,7 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "680998035259dcfcafe653688bf2aa6d3e2dc05e98be6ab46afb089dc84f1df8" dependencies = [ - "proc-macro-crate 3.5.0", + "proc-macro-crate 1.3.1", "proc-macro2", "quote", "syn 2.0.119", @@ -5523,7 +5528,7 @@ dependencies = [ "once_cell", "socket2 0.5.10", "tracing", - "windows-sys 0.61.2", + "windows-sys 0.52.0", ] [[package]] @@ -6065,7 +6070,7 @@ dependencies = [ "errno", "libc", "linux-raw-sys 0.4.15", - "windows-sys 0.59.0", + "windows-sys 0.52.0", ] [[package]] @@ -6078,7 +6083,7 @@ dependencies = [ "errno", "libc", "linux-raw-sys 0.12.1", - "windows-sys 0.61.2", + "windows-sys 0.52.0", ] [[package]] @@ -6137,7 +6142,7 @@ dependencies = [ "security-framework", "security-framework-sys", "webpki-root-certs", - "windows-sys 0.61.2", + "windows-sys 0.52.0", ] [[package]] @@ -6768,7 +6773,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c3d1e2c7f27f8d4cb10542a02c49005dbd6e93095799d6f3be745fae9f8fedd4" dependencies = [ "libc", - "windows-sys 0.61.2", + "windows-sys 0.60.2", ] [[package]] @@ -7658,7 +7663,7 @@ dependencies = [ "getrandom 0.3.4", "once_cell", "rustix 1.1.4", - "windows-sys 0.61.2", + "windows-sys 0.52.0", ] [[package]] @@ -8480,7 +8485,7 @@ checksum = "f2f6fb2847f6742cd76af783a2a2c49e9375d0a111c7bef6f71cd9e738c72d6e" dependencies = [ "memoffset", "tempfile", - "windows-sys 0.61.2", + "windows-sys 0.60.2", ] [[package]] @@ -9669,7 +9674,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7d6f32a0ff4a9f6f01231eb2059cc85479330739333e0e58cadf03b6af2cca10" dependencies = [ "cfg-if", - "windows-sys 0.61.2", + "windows-sys 0.60.2", ] [[package]] @@ -9850,9 +9855,9 @@ dependencies = [ [[package]] name = "zbus" -version = "5.18.0" +version = "5.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe18fb60dc696039e738717b76eaea21e7a4489bbb1885020b43c94236d7e98a" +checksum = "5db4be7c075cb421e4b7ee645541604239bd243ba7c357511f4ff3a74b555907" dependencies = [ "async-broadcast", "async-executor", @@ -9885,14 +9890,14 @@ dependencies = [ [[package]] name = "zbus_macros" -version = "5.18.0" +version = "5.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe96480bed92df2b442a1a30df364e12d08eed03aeb061f2b8dc6afb2be91119" +checksum = "2990635d09ade6df1868f72f8cac69a876a90981e8bd3c40b1be413f8dc88f40" dependencies = [ "proc-macro-crate 3.5.0", "proc-macro2", "quote", - "syn 2.0.119", + "syn 3.0.3", "zbus_names", "zvariant", "zvariant_utils", @@ -9909,6 +9914,15 @@ dependencies = [ "zvariant", ] +[[package]] +name = "zcheapstr" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1afec51604565183aeb5c54c20aeab286120d4e4460f7f76e3e8bb8c0d99473" +dependencies = [ + "serde", +] + [[package]] name = "zerocopy" version = "0.8.55" @@ -10099,40 +10113,41 @@ dependencies = [ [[package]] name = "zvariant" -version = "5.13.1" +version = "5.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bee2a0bcd2a907786a456fff45aaaaf54c9ba5f50b71ae9ec1a4edd200c94911" +checksum = "c1d34c27cc6cdd1f458427519dd6b8612f7b7e3f7b9a0b2355d041dda9869147" dependencies = [ "endi", "enumflags2", "serde", "winnow 1.0.4", + "zcheapstr", "zvariant_derive", "zvariant_utils", ] [[package]] name = "zvariant_derive" -version = "5.13.1" +version = "5.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38a708216a18780796770bfe3f4739c7c83a3e8f789b755534bbbc06e4e23e12" +checksum = "864155e69b4352db0c7f374917bf45d1e0c8d17659c8b3dbf9795f3673f8c497" dependencies = [ "proc-macro-crate 3.5.0", "proc-macro2", "quote", - "syn 2.0.119", + "syn 3.0.3", "zvariant_utils", ] [[package]] name = "zvariant_utils" -version = "3.5.0" +version = "4.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90cb9383f9b45290407a1258b202d3f8f01db719eb60b4e4055c6375af4fc7c7" +checksum = "bad0294361a320b694a328460dc73add56c306150f5cb6bfafc44446120008a3" dependencies = [ "proc-macro2", "quote", "serde", - "syn 2.0.119", + "syn 3.0.3", "winnow 1.0.4", ] diff --git a/Changelog.md b/Changelog.md index e6a0704d7..ffce80cc6 100644 --- a/Changelog.md +++ b/Changelog.md @@ -16,6 +16,7 @@ 修复过长的错误提示撑满界面的问题(右键复制仍为完整内容) 修复部分错误提示显示为 [object Object] 的问题 修复 i18n 清理脚本因导入方式错误而无法运行的问题 +修复 Linux 桌面环境下主题切换时应用外观不跟随的问题
✨ 新增功能 diff --git a/scripts/dev-service.mjs b/scripts/dev-service.mjs index a44d2d61b..b5c093509 100644 --- a/scripts/dev-service.mjs +++ b/scripts/dev-service.mjs @@ -80,10 +80,7 @@ async function writeInstalledFingerprint(fingerprint) { ) } -function windowsElevationInvocation( - installer, - environment = process.env, -) { +function windowsElevationInvocation(installer, environment = process.env) { const script = [ "$ErrorActionPreference = 'Stop'", `$installer = [Environment]::GetEnvironmentVariable('${developmentServiceInstallerEnvironment}', 'Process')`, diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index b9b2485de..207406dee 100755 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -103,8 +103,7 @@ arc-swap = "1.9.2" tokio-rustls = "0.26.4" rustls = { version = "0.23.43", features = ["ring"] } webpki-roots = "1.0.9" -# Use the git repo until the next release after v2.0.0. -dark-light = { git = "https://github.com/rust-dark-light/dark-light" } +dark-light = "3.0.0" bytes = "1.12.1" tokio-util = { version = "0.7.19", features = ["time"] } diff --git a/src-tauri/src/core/notification.rs b/src-tauri/src/core/notification.rs index e1745db30..a9d2d4ecd 100644 --- a/src-tauri/src/core/notification.rs +++ b/src-tauri/src/core/notification.rs @@ -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)), } } diff --git a/src-tauri/src/utils/resolve/mod.rs b/src-tauri/src/utils/resolve/mod.rs index 73cc815a6..f7b6c55e9 100644 --- a/src-tauri/src/utils/resolve/mod.rs +++ b/src-tauri/src/utils/resolve/mod.rs @@ -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); }