From d539791b313df5e313aeef5204ecb68148e330d4 Mon Sep 17 00:00:00 2001 From: Cooper-X-Oak Date: Thu, 30 Apr 2026 13:32:34 +0800 Subject: [PATCH] =?UTF-8?q?fix(windows):=20=E7=BC=BA=E5=A4=B1=E6=89=98?= =?UTF-8?q?=E7=9B=98=E5=9B=BE=E6=A0=87=E6=97=B6=E7=BB=A7=E7=BB=AD=E5=90=AF?= =?UTF-8?q?=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- openless-all/app/src-tauri/src/lib.rs | 44 +++++++++++++++------------ 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/openless-all/app/src-tauri/src/lib.rs b/openless-all/app/src-tauri/src/lib.rs index 915050d8..5a0801e5 100644 --- a/openless-all/app/src-tauri/src/lib.rs +++ b/openless-all/app/src-tauri/src/lib.rs @@ -94,26 +94,30 @@ pub fn run() { // 与 Swift `StatusBarIcon.swift` 行为一致:用全彩 AppIcon,**不**走 template 模式 // (走 template 会被 macOS 染成单色 → 看起来像个黑方块)。 - let _tray = TrayIconBuilder::with_id("main-tray") - .icon(app.default_window_icon().unwrap().clone()) - .icon_as_template(false) - .menu(&menu) - .show_menu_on_left_click(false) - .on_menu_event(|app, event| match event.id.as_ref() { - "toggle" => show_main_window(app), - "quit" => app.exit(0), - _ => {} - }) - .on_tray_icon_event(|tray, event| { - if let TrayIconEvent::Click { - button: MouseButton::Left, - .. - } = event - { - show_main_window(tray.app_handle()); - } - }) - .build(app)?; + if let Some(icon) = app.default_window_icon() { + let _tray = TrayIconBuilder::with_id("main-tray") + .icon(icon.clone()) + .icon_as_template(false) + .menu(&menu) + .show_menu_on_left_click(false) + .on_menu_event(|app, event| match event.id.as_ref() { + "toggle" => show_main_window(app), + "quit" => app.exit(0), + _ => {} + }) + .on_tray_icon_event(|tray, event| { + if let TrayIconEvent::Click { + button: MouseButton::Left, + .. + } = event + { + show_main_window(tray.app_handle()); + } + }) + .build(app)?; + } else { + log::warn!("[startup] default window icon missing; tray icon disabled"); + } // Spin up hotkey listener; coordinator owns the lifecycle. let app_handle = app.handle().clone();