25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。
TypeScript aicliclickhousedatabasedatabase-clientdatabase-managementdockerguimcpmongodbmysqlpostgresqlredisrustsql-serversqlitetaurivue
fix(desktop): keep the macOS app icon dark in dark theme
_Mr丶s ゛😁®a1824c9079e6
diff --git a/apps/desktop/src/composables/useTheme.ts b/apps/desktop/src/composables/useTheme.tsindex c6cd237370..a2579451da 100644--- a/apps/desktop/src/composables/useTheme.ts+++ b/apps/desktop/src/composables/useTheme.ts@@ -28,6 +28,7 @@ import {import { safeLocalStorageGet, safeLocalStorageSet } from "@/lib/backend/safeStorage";import { isTauriRuntime } from "@/lib/backend/tauriRuntime";import { persistAppAppearancePatch } from "@/lib/app/appAppearance";+import { isMacOS } from "@/lib/backend/platform";function isLinuxTauriRuntime() {return isTauriRuntime() && typeof navigator !== "undefined" && /linux/i.test(navigator.userAgent);@@ -100,6 +101,8 @@ function writeRootToken(cssVar: string, value: string, options?: { debounceMs?:let mediaQuery: MediaQueryList | null = null;let isListeningForSystemTheme = false;let cachedTauriWindow: typeof import("@tauri-apps/api/window") | null = null;+let macOSAppIconSyncQueue: Promise<void> = Promise.resolve();+let lastSyncedMacOSAppIconAppearance: boolean | null = null;function readSystemPrefersDark() {if (typeof window === "undefined" || typeof window.matchMedia !== "function") return false;@@ -118,6 +121,24 @@ function setupSystemThemeListener() {isListeningForSystemTheme = true;}+export function syncMacOSAppIconAppearance(isDark: boolean): Promise<void> {+ if (!isTauriRuntime() || !isMacOS()) return Promise.resolve();+ if (lastSyncedMacOSAppIconAppearance === isDark) return macOSAppIconSyncQueue;+ lastSyncedMacOSAppIconAppearance = isDark;+ macOSAppIconSyncQueue = macOSAppIconSyncQueue+ .catch(() => {})+ .then(async () => {+ try {+ const { invoke } = await import("@tauri-apps/api/core");+ await invoke("set_macos_app_icon_appearance", { isDark });+ } catch {+ // The bundle icon can fail to persist when the installed .app is read-only.+ // The Rust side logs the native failure while the running icon still updates.+ }+ });+ return macOSAppIconSyncQueue;+}+function applyThemePalette() {if (typeof document === "undefined") return;@@ -146,6 +167,11 @@ function applyTheme() {requestAnimationFrame(() => doc.classList.remove("disable-transitions"));if (!isTauriRuntime()) return;+ // Keep the persistent macOS app-bundle icon in step with the resolved app+ // appearance, including system-theme changes. The backend preserves an+ // explicitly selected black icon when the app is in light mode.+ void syncMacOSAppIconAppearance(dark);+const tauriTheme = getTauriThemeForMode(themeMode.value);// Tauri owns the Linux GTK preference. Calling setTheme(null) here forces it// to light, so only skip the native system-theme write and keep explicit modes.diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.tomlindex 314c0a2e34..c51a77c94d 100644--- a/src-tauri/Cargo.toml+++ b/src-tauri/Cargo.toml@@ -89,8 +89,8 @@ tauri = { version = "2.10.3", features = ["test"] }[target.'cfg(target_os = "macos")'.dependencies]objc2 = { version = "0.6.4", default-features = false, features = ["std"] }-objc2-app-kit = { version = "0.3.2", default-features = false, features = ["NSApplication", "NSButton", "NSControl", "NSDockTile", "NSEvent", "NSImage", "NSResponder", "NSView", "NSWindow"] }-objc2-foundation = { version = "0.3.2", default-features = false, features = ["NSData", "NSString"] }+objc2-app-kit = { version = "0.3.2", default-features = false, features = ["NSApplication", "NSButton", "NSControl", "NSDockTile", "NSEvent", "NSImage", "NSResponder", "NSView", "NSWindow", "NSWorkspace"] }+objc2-foundation = { version = "0.3.2", default-features = false, features = ["NSBundle", "NSData", "NSString"] }[target.'cfg(target_os = "linux")'.dependencies]libloading = "0.8"diff --git a/src-tauri/src/commands/app_settings.rs b/src-tauri/src/commands/app_settings.rsindex f605b09aeb..49c2e78e56 100644--- a/src-tauri/src/commands/app_settings.rs+++ b/src-tauri/src/commands/app_settings.rs@@ -98,6 +98,25 @@ pub async fn update_app_appearance_settings(state.storage.update_app_appearance_settings(&patch).await}+#[tauri::command]+pub async fn set_macos_app_icon_appearance(+ app: AppHandle,+ state: State<'_, Arc<AppState>>,+ is_dark: bool,+) -> Result<(), String> {+ #[cfg(target_os = "macos")]+ {+ let desktop_settings = state.storage.load_desktop_settings().await?;+ crate::apply_macos_app_appearance_icon(&app, is_dark, desktop_settings.icon_theme)+ .map_err(|error| error.to_string())+ }+ #[cfg(not(target_os = "macos"))]+ {+ let _ = (app, state, is_dark);+ Ok(())+ }+}+#[tauri::command]pub async fn set_app_locale(app: AppHandle,diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rsindex c20d4e7b44..45334cf9fa 100644--- a/src-tauri/src/lib.rs+++ b/src-tauri/src/lib.rs@@ -114,6 +114,8 @@ const BLACK_APP_ICON: tauri::image::Image<'_> = tauri::include_image!("icons/icoconst MACOS_DEFAULT_APP_ICON: &[u8] = include_bytes!("../icons/icon.icns");#[cfg(target_os = "macos")]const MACOS_DARK_APP_ICON: &[u8] = include_bytes!("../icons/icon-macos-dark.icns");+#[cfg(target_os = "macos")]+static MACOS_APP_APPEARANCE_DARK: std::sync::atomic::AtomicBool = std::sync::atomic::AtomicBool::new(false);pub(crate) fn apply_debug_log_level(debug_logging_enabled: bool) {log::set_max_level(if debug_logging_enabled { log::LevelFilter::Debug } else { log::LevelFilter::Off });@@ -952,10 +954,14 @@ fn setup_desktop_tray<R: tauri::Runtime, M: Manager<R>>(}#[cfg(target_os = "macos")]-fn apply_macos_app_icon_theme(app: &tauri::AppHandle, icon_theme: DesktopIconTheme) -> tauri::Result<()> {+fn apply_macos_app_icon_theme(+ app: &tauri::AppHandle,+ icon_theme: DesktopIconTheme,+ persist_bundle_icon: bool,+) -> tauri::Result<()> {use objc2::{AllocAnyThread, MainThreadMarker};- use objc2_app_kit::{NSApplication, NSImage};- use objc2_foundation::NSData;+ use objc2_app_kit::{NSApplication, NSImage, NSWorkspace, NSWorkspaceIconCreationOptions};+ use objc2_foundation::{NSBundle, NSData, NSString};let icon_bytes = match icon_theme {DesktopIconTheme::Default => MACOS_DEFAULT_APP_ICON,@@ -966,9 +972,31 @@ fn apply_macos_app_icon_theme(app: &tauri::AppHandle, icon_theme: DesktopIconThe// app switcher reflect the selected theme immediately.let marker = unsafe { MainThreadMarker::new_unchecked() };let application = NSApplication::sharedApplication(marker);+ let workspace = NSWorkspace::sharedWorkspace();+ let app_bundle_path = NSBundle::mainBundle().bundlePath();let data = NSData::with_bytes(icon_bytes);if let Some(icon) = NSImage::initWithData(NSImage::alloc(), &data) {unsafe { application.setApplicationIconImage(Some(&icon)) };++ // NSApplication only changes the icon for this process lifetime.+ // Persist the selected icon on the app bundle so Finder and the+ // Dock keep showing it after DBX exits. A nil image removes the+ // custom icon and restores the bundle's packaged default.+ if persist_bundle_icon {+ let persistent_icon = match icon_theme {+ DesktopIconTheme::Default => None,+ DesktopIconTheme::Black => Some(&*icon),+ };+ if app_bundle_path.hasSuffix(&NSString::from_str(".app"))+ && !workspace.setIcon_forFile_options(+ persistent_icon,+ &app_bundle_path,+ NSWorkspaceIconCreationOptions::empty(),+ )+ {+ log::warn!("Failed to persist the selected macOS app icon; the app bundle may not be writable");+ }+ }} else {log::warn!("Failed to decode the selected macOS application icon");}@@ -990,10 +1018,10 @@ fn apply_macos_development_dock_badge(app: &tauri::AppHandle) -> tauri::Result<(})}-fn apply_desktop_icon_theme(app: &tauri::AppHandle, icon_theme: DesktopIconTheme) -> tauri::Result<()> {+pub(crate) fn apply_desktop_icon_theme(app: &tauri::AppHandle, icon_theme: DesktopIconTheme) -> tauri::Result<()> {#[cfg(target_os = "macos")]{- apply_macos_app_icon_theme(app, icon_theme)+ apply_macos_app_icon_theme(app, icon_theme, true)}#[cfg(not(target_os = "macos"))]@@ -1011,6 +1039,21 @@ fn apply_desktop_icon_theme(app: &tauri::AppHandle, icon_theme: DesktopIconThemeOk(())}+#[cfg(target_os = "macos")]+pub(crate) fn apply_macos_app_appearance_icon(+ app: &tauri::AppHandle,+ is_dark: bool,+ selected_icon_theme: DesktopIconTheme,+) -> tauri::Result<()> {+ MACOS_APP_APPEARANCE_DARK.store(is_dark, std::sync::atomic::Ordering::Release);+ let icon_theme = if is_dark || selected_icon_theme == DesktopIconTheme::Black {+ DesktopIconTheme::Black+ } else {+ DesktopIconTheme::Default+ };+ apply_macos_app_icon_theme(app, icon_theme, true)+}+fn apply_desktop_tray_icon_theme(app: &tauri::AppHandle, _icon_theme: DesktopIconTheme) -> tauri::Result<()> {if let Some(_tray) = app.tray_by_id(DESKTOP_TRAY_ID) {#[cfg(target_os = "windows")]@@ -1039,7 +1082,15 @@ fn apply_desktop_tray_icon_theme(app: &tauri::AppHandle, _icon_theme: DesktopIcopub(crate) fn apply_desktop_settings(app: &tauri::AppHandle, desktop_settings: &DesktopSettings) -> tauri::Result<()> {apply_debug_log_level(desktop_settings.debug_logging_enabled);- apply_desktop_icon_theme(app, desktop_settings.icon_theme)?;+ #[cfg(target_os = "macos")]+ let icon_theme = if MACOS_APP_APPEARANCE_DARK.load(std::sync::atomic::Ordering::Acquire) {+ DesktopIconTheme::Black+ } else {+ desktop_settings.icon_theme+ };+ #[cfg(not(target_os = "macos"))]+ let icon_theme = desktop_settings.icon_theme;+ apply_desktop_icon_theme(app, icon_theme)?;if should_setup_desktop_tray(std::env::consts::OS, desktop_settings.show_tray_icon, linux_appindicator_available()){if let Some(tray) = app.tray_by_id(DESKTOP_TRAY_ID) {@@ -1681,6 +1732,9 @@ pub fn run() {let migration_gate = Arc::new(migration_gate::MigrationGate::new(migration_ready));app.manage(migration_gate.clone());let desktop_settings = tauri::async_runtime::block_on(storage.load_desktop_settings()).unwrap_or_default();+ #[cfg(target_os = "macos")]+ let app_appearance =+ tauri::async_runtime::block_on(storage.load_app_appearance_settings()).unwrap_or_default();app.handle().plugin(tauri_plugin_log::Builder::default().timezone_strategy(tauri_plugin_log::TimezoneStrategy::UseLocal)@@ -1832,6 +1886,20 @@ pub fn run() {) {setup_desktop_tray(app, desktop_settings.icon_theme)?;}+ #[cfg(target_os = "macos")]+ match app_appearance.theme_mode.as_deref() {+ Some("dark" | "soft-dark") => {+ apply_macos_app_appearance_icon(app.handle(), true, desktop_settings.icon_theme)?;+ }+ Some("light" | "soft-light") => {+ apply_macos_app_appearance_icon(app.handle(), false, desktop_settings.icon_theme)?;+ }+ // System mode is resolved by the renderer's matchMedia listener+ // as soon as startup hydration finishes. Leave the persisted+ // bundle icon intact until then to avoid briefly forcing light.+ _ => {}+ }+ #[cfg(not(target_os = "macos"))]apply_desktop_icon_theme(app.handle(), desktop_settings.icon_theme)?;#[cfg(target_os = "macos")]apply_macos_development_dock_badge(app.handle())?;@@ -1960,6 +2028,7 @@ pub fn run() {commands::app_settings::save_max_retries,commands::app_settings::load_app_appearance_settings,commands::app_settings::update_app_appearance_settings,+ commands::app_settings::set_macos_app_icon_appearance,commands::app_settings::set_app_locale,commands::app_settings::complete_app_close,commands::app_settings::mark_frontend_ready,diff --git a/src-tauri/src/migration_gate.rs b/src-tauri/src/migration_gate.rsindex 2313799ba6..1d4bc6b28e 100644--- a/src-tauri/src/migration_gate.rs+++ b/src-tauri/src/migration_gate.rs@@ -46,6 +46,7 @@ pub fn allowed_command(command: &str) -> bool {| "get_platform"| "load_app_appearance_settings"| "update_app_appearance_settings"+ | "set_macos_app_icon_appearance"| "set_app_locale")}