diff --git a/lib/tray.ts b/lib/tray.ts index 5c43d8e..3c87983 100644 --- a/lib/tray.ts +++ b/lib/tray.ts @@ -25,18 +25,19 @@ async function getTray() { } async function resolveTrayIconForTheme() { - const existingTheme = usePersistedStore.getState().theme - if (existingTheme) { - return existingTheme === 'dark' ? 'icons/favicon/icon.png' : 'icons/favicon/icon-light.png' - } + // const existingTheme = usePersistedStore.getState().theme + // if (existingTheme) { + // return existingTheme === 'dark' ? 'icons/favicon/icon.png' : 'icons/favicon/icon-light.png' + // } let theme: 'light' | 'dark' = 'dark' try { - const oneTheme = await invoke('get_system_theme') - const currentWindow = getCurrentWindow() - const twoTheme = await currentWindow.theme() + const detectedTheme = (await invoke('get_system_theme')) as + | 'light' + | 'dark' + | 'unknown' - if (oneTheme !== twoTheme) { + if (detectedTheme === 'unknown') { const answer = await ask( 'Could not determine your system theme, please select the correct one below', { @@ -52,13 +53,13 @@ async function resolveTrayIconForTheme() { theme = 'light' } } else { - theme = oneTheme + theme = detectedTheme } } catch {} console.log('[resolveTrayIconForTheme] theme', theme) - usePersistedStore.setState({ theme }) + usePersistedStore.setState({ theme: undefined }) const pickedPath = theme === 'dark' ? 'icons/favicon/icon.png' : 'icons/favicon/icon-light.png' console.log('[resolveTrayIconForTheme] pickedPath', pickedPath) @@ -144,10 +145,10 @@ export async function initTray() { try { console.log('[initTray]') - const initialIcon = await resolveTrayIconForTheme() + // const initialIcon = await resolveTrayIconForTheme() await TrayIcon.new({ id: 'main-tray', - icon: initialIcon!, + // icon: initialIcon!, tooltip: 'Rclone', menuOnLeftClick: true, action: async (event: TrayIconEvent) => { diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 31eb23b..eb3b70c 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -258,6 +258,7 @@ name = "app" version = "2.7.10" dependencies = [ "cocoa", + "dark-light", "fix-path-env", "log", "machine-uid", @@ -285,7 +286,7 @@ dependencies = [ "tauri-plugin-store", "tauri-plugin-updater", "x11rb", - "zbus", + "zbus 5.9.0", "zip 0.6.6", ] @@ -343,7 +344,7 @@ dependencies = [ "wayland-backend", "wayland-client", "wayland-protocols", - "zbus", + "zbus 5.9.0", ] [[package]] @@ -384,6 +385,17 @@ dependencies = [ "slab", ] +[[package]] +name = "async-fs" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8034a681df4aed8b8edbd7fbe472401ecf009251c8b40556b304567052e294c5" +dependencies = [ + "async-lock", + "blocking", + "futures-lite", +] + [[package]] name = "async-io" version = "2.5.0" @@ -1166,6 +1178,22 @@ dependencies = [ "syn 2.0.104", ] +[[package]] +name = "dark-light" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a76fa97167fa740dcdbfe18e8895601e1bc36525f09b044e00916e717c03a3c" +dependencies = [ + "dconf_rs", + "detect-desktop-environment", + "dirs 4.0.0", + "objc", + "rust-ini", + "web-sys", + "winreg 0.10.1", + "zbus 4.4.0", +] + [[package]] name = "darling" version = "0.20.11" @@ -1207,6 +1235,12 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5c297a1c74b71ae29df00c3e22dd9534821d60eb9af5a0192823fa2acea70c2a" +[[package]] +name = "dconf_rs" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7046468a81e6a002061c01e6a7c83139daf91b11c30e66795b13217c2d885c8b" + [[package]] name = "debugid" version = "0.8.0" @@ -1282,6 +1316,12 @@ dependencies = [ "unicode-xid", ] +[[package]] +name = "detect-desktop-environment" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21d8ad60dd5b13a4ee6bd8fa2d5d88965c597c67bce32b5fc49c94f55cb50810" + [[package]] name = "digest" version = "0.10.7" @@ -1395,6 +1435,12 @@ dependencies = [ "syn 2.0.104", ] +[[package]] +name = "dlv-list" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0688c2a7f92e427f44895cd63841bff7b29f8d7a1648b9e7e07a4a365b2e1257" + [[package]] name = "document-features" version = "0.2.11" @@ -3292,6 +3338,19 @@ dependencies = [ "libc", ] +[[package]] +name = "nix" +version = "0.29.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "71e2746dc3a24dd78b3cfcb7be93368c6de9963d30f43a6a73998a9cf4b17b46" +dependencies = [ + "bitflags 2.9.1", + "cfg-if", + "cfg_aliases 0.2.1", + "libc", + "memoffset", +] + [[package]] name = "nix" version = "0.30.1" @@ -3332,7 +3391,7 @@ dependencies = [ "mac-notification-sys", "serde", "tauri-winrt-notification", - "zbus", + "zbus 5.9.0", ] [[package]] @@ -3746,6 +3805,16 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d" +[[package]] +name = "ordered-multimap" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccd746e37177e1711c20dd619a1620f34f5c8b569c53590a72dedd5344d8924a" +dependencies = [ + "dlv-list", + "hashbrown 0.12.3", +] + [[package]] name = "ordered-stream" version = "0.2.0" @@ -4768,6 +4837,16 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "rust-ini" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6d5f2436026b4f6e79dc829837d467cc7e9a55ee40e750d716713540715a2df" +dependencies = [ + "cfg-if", + "ordered-multimap", +] + [[package]] name = "rust_decimal" version = "1.37.2" @@ -6106,7 +6185,7 @@ dependencies = [ "thiserror 2.0.14", "url", "windows", - "zbus", + "zbus 5.9.0", ] [[package]] @@ -6200,7 +6279,7 @@ dependencies = [ "thiserror 2.0.14", "tracing", "windows-sys 0.60.2", - "zbus", + "zbus 5.9.0", ] [[package]] @@ -8028,6 +8107,16 @@ dependencies = [ "rustix 1.0.8", ] +[[package]] +name = "xdg-home" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec1cdab258fb55c0da61328dc52c8764709b249011b2cad0454c72f0bf10a1f6" +dependencies = [ + "libc", + "windows-sys 0.59.0", +] + [[package]] name = "yoke" version = "0.8.0" @@ -8052,6 +8141,44 @@ dependencies = [ "synstructure", ] +[[package]] +name = "zbus" +version = "4.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb97012beadd29e654708a0fdb4c84bc046f537aecfde2c3ee0a9e4b4d48c725" +dependencies = [ + "async-broadcast", + "async-executor", + "async-fs", + "async-io", + "async-lock", + "async-process", + "async-recursion", + "async-task", + "async-trait", + "blocking", + "enumflags2", + "event-listener", + "futures-core", + "futures-sink", + "futures-util", + "hex", + "nix 0.29.0", + "ordered-stream", + "rand 0.8.5", + "serde", + "serde_repr", + "sha1", + "static_assertions", + "tracing", + "uds_windows", + "windows-sys 0.52.0", + "xdg-home", + "zbus_macros 4.4.0", + "zbus_names 3.0.0", + "zvariant 4.2.0", +] + [[package]] name = "zbus" version = "5.9.0" @@ -8081,9 +8208,22 @@ dependencies = [ "uds_windows", "windows-sys 0.59.0", "winnow 0.7.12", - "zbus_macros", - "zbus_names", - "zvariant", + "zbus_macros 5.9.0", + "zbus_names 4.2.0", + "zvariant 5.6.0", +] + +[[package]] +name = "zbus_macros" +version = "4.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "267db9407081e90bbfa46d841d3cbc60f59c0351838c4bc65199ecd79ab1983e" +dependencies = [ + "proc-macro-crate 3.3.0", + "proc-macro2", + "quote", + "syn 2.0.104", + "zvariant_utils 2.1.0", ] [[package]] @@ -8096,9 +8236,20 @@ dependencies = [ "proc-macro2", "quote", "syn 2.0.104", - "zbus_names", - "zvariant", - "zvariant_utils", + "zbus_names 4.2.0", + "zvariant 5.6.0", + "zvariant_utils 3.2.0", +] + +[[package]] +name = "zbus_names" +version = "3.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b9b1fef7d021261cc16cba64c351d291b715febe0fa10dc3a443ac5a5022e6c" +dependencies = [ + "serde", + "static_assertions", + "zvariant 4.2.0", ] [[package]] @@ -8110,7 +8261,7 @@ dependencies = [ "serde", "static_assertions", "winnow 0.7.12", - "zvariant", + "zvariant 5.6.0", ] [[package]] @@ -8254,6 +8405,19 @@ dependencies = [ "pkg-config", ] +[[package]] +name = "zvariant" +version = "4.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2084290ab9a1c471c38fc524945837734fbf124487e105daec2bb57fd48c81fe" +dependencies = [ + "endi", + "enumflags2", + "serde", + "static_assertions", + "zvariant_derive 4.2.0", +] + [[package]] name = "zvariant" version = "5.6.0" @@ -8265,8 +8429,21 @@ dependencies = [ "serde", "url", "winnow 0.7.12", - "zvariant_derive", - "zvariant_utils", + "zvariant_derive 5.6.0", + "zvariant_utils 3.2.0", +] + +[[package]] +name = "zvariant_derive" +version = "4.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73e2ba546bda683a90652bac4a279bc146adad1386f25379cf73200d2002c449" +dependencies = [ + "proc-macro-crate 3.3.0", + "proc-macro2", + "quote", + "syn 2.0.104", + "zvariant_utils 2.1.0", ] [[package]] @@ -8279,7 +8456,18 @@ dependencies = [ "proc-macro2", "quote", "syn 2.0.104", - "zvariant_utils", + "zvariant_utils 3.2.0", +] + +[[package]] +name = "zvariant_utils" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c51bcff7cc3dbb5055396bcf774748c3dab426b4b8659046963523cee4808340" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.104", ] [[package]] diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 0628468..1dd0c67 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -45,6 +45,7 @@ tauri-plugin-clipboard-manager = "2.3.0" tauri-plugin-prevent-default = "3" reqwest = { version = "0.11", features = ["json"] } sysinfo = "0.37" +dark-light = "1.1.1" [target.'cfg(target_os = "macos")'.dependencies] cocoa = "0.26" diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 0c8c703..0b1bf10 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -250,96 +250,13 @@ fn get_uid() -> String { #[tauri::command] fn get_system_theme() -> String { - #[cfg(target_os = "macos")] - { - use std::process::Command; - if let Ok(output) = Command::new("defaults") - .args(&["read", "-g", "AppleInterfaceStyle"]) - .output() - { - if output.status.success() { - let out = String::from_utf8_lossy(&output.stdout).to_ascii_lowercase(); - if out.contains("dark") { - return "dark".to_string(); - } - } - } - return "light".to_string(); - } - - #[cfg(target_os = "windows")] - { - use std::process::Command; - if let Ok(output) = Command::new("reg").args(&[ - "query", - r"HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize", - "/v", - "AppsUseLightTheme", - ]).output() { - if output.status.success() { - let out = String::from_utf8_lossy(&output.stdout).to_ascii_lowercase(); - if out.contains("0x0") || out.contains("0x00000000") { - return "dark".to_string(); - } - if out.contains("0x1") || out.contains("0x00000001") { - return "light".to_string(); - } - } - } - return "light".to_string(); - } - - #[cfg(target_os = "linux")] - { - use std::process::Command; - - // GNOME color-scheme (prefer-dark) - if let Ok(output) = Command::new("gsettings") - .args(&["get", "org.gnome.desktop.interface", "color-scheme"]) - .output() - { - if output.status.success() { - let out = String::from_utf8_lossy(&output.stdout).to_ascii_lowercase(); - if out.contains("dark") { - return "dark".to_string(); - } - } - } - - // GNOME gtk-theme name contains "dark" - if let Ok(output) = Command::new("gsettings") - .args(&["get", "org.gnome.desktop.interface", "gtk-theme"]) - .output() - { - if output.status.success() { - let out = String::from_utf8_lossy(&output.stdout).to_ascii_lowercase(); - if out.contains("dark") { - return "dark".to_string(); - } - } - } - - // KDE color scheme via kreadconfig5 - if let Ok(output) = Command::new("kreadconfig5") - .args(&["--group", "General", "--key", "ColorScheme"]) - .output() - { - if output.status.success() { - let out = String::from_utf8_lossy(&output.stdout).to_ascii_lowercase(); - if out.contains("dark") { - return "dark".to_string(); - } - } - } - - return "light".to_string(); - } - - #[cfg(not(any(target_os = "macos", target_os = "windows", target_os = "linux")))] - { - "dark".to_string() + match dark_light::detect() { + dark_light::Mode::Dark => "dark".to_string(), + dark_light::Mode::Light => "light".to_string(), + dark_light::Mode::Default => "unknown".to_string(), } } + #[tauri::command] fn is_rclone_running(port: Option) -> bool {