diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index c6b45f7..d436d3b 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -117,15 +117,31 @@ fn build_tray(app: &AppHandle) -> tauri::Result<()> { } }); - // 菜单栏用单色模板图标(macOS 会随浅色/深色菜单栏自动反色,看着才像原生) - match tauri::image::Image::from_bytes(include_bytes!("../icons/tray-template.png")) { - Ok(ic) => builder = builder.icon(ic).icon_as_template(true), - Err(_) => { - if let Some(icon) = app.default_window_icon().cloned() { - builder = builder.icon(icon); + // 托盘图标按平台分(icon_as_template 只在 macOS 生效,Windows 是 no-op): + // - macOS:单色模板图标 + icon_as_template(true),随菜单栏深浅自动反色。 + // - Windows/Linux:template 不反色、直接渲染像素。tray-template.png 是「黑底 + IW 镂空」, + // 深色任务栏上黑底融入背景、镂空透出背景 ⇒ 图标「看不见」。所以这里用实心主图标 + // default_window_icon(黑底白 IW),深色靠白 IW、浅色靠黑底方块,两种背景都清晰;不加描边。 + #[cfg(target_os = "macos")] + { + match tauri::image::Image::from_bytes(include_bytes!("../icons/tray-template.png")) { + Ok(ic) => builder = builder.icon(ic).icon_as_template(true), + Err(_) => { + if let Some(icon) = app.default_window_icon().cloned() { + builder = builder.icon(icon); + } } } } + #[cfg(not(target_os = "macos"))] + { + if let Some(icon) = app.default_window_icon().cloned() { + builder = builder.icon(icon); + } else if let Ok(ic) = tauri::image::Image::from_bytes(include_bytes!("../icons/tray-template.png")) { + // 兜底:极端情况拿不到主图标,仍给一张,避免空托盘 + builder = builder.icon(ic); + } + } builder.build(app)?; Ok(()) }