From 9b87cd53e1380350f6a6dae8c2fde9d330be57c7 Mon Sep 17 00:00:00 2001 From: oomeow Date: Mon, 22 Jun 2026 03:28:39 +0800 Subject: [PATCH] fix(tray): tray icon flickering on macOS (#7335) * fix(tray): tray icon flickering on macOS * refactor(tray): use explicit cfg blocks for template logic --- src-tauri/src/core/tray/mod.rs | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src-tauri/src/core/tray/mod.rs b/src-tauri/src/core/tray/mod.rs index 1399e3c15..8dbdc0603 100644 --- a/src-tauri/src/core/tray/mod.rs +++ b/src-tauri/src/core/tray/mod.rs @@ -255,16 +255,19 @@ impl Tray { let (_is_custom_icon, icon_bytes) = TrayState::get_tray_icon(verge).await; - logging_error!( - Type::Tray, - tray.set_icon(Some(tauri::image::Image::from_bytes(&icon_bytes)?)) - ); + let template = { + #[cfg(target_os = "macos")] + { + verge.tray_icon.as_ref().is_none_or(|v| v == "monochrome") + } + #[cfg(not(target_os = "macos"))] + { + false + } + }; + let icon = Some(tauri::image::Image::from_bytes(&icon_bytes)?); - #[cfg(target_os = "macos")] - { - let is_colorful = verge.tray_icon.as_deref().unwrap_or("monochrome") == "colorful"; - logging_error!(Type::Tray, tray.set_icon_as_template(!is_colorful)); - } + logging_error!(Type::Tray, tray.set_icon_with_as_template(icon, template)); Ok(()) }