diff --git a/easytier-gui/src/composables/tray.ts b/easytier-gui/src/composables/tray.ts index b5ed0a24..167444a8 100644 --- a/easytier-gui/src/composables/tray.ts +++ b/easytier-gui/src/composables/tray.ts @@ -2,10 +2,26 @@ import { invoke } from '@tauri-apps/api/core' import { Menu, MenuItem, PredefinedMenuItem } from '@tauri-apps/api/menu' import { TrayIcon } from '@tauri-apps/api/tray' import { getCurrentWindow } from '@tauri-apps/api/window' +import { type } from '@tauri-apps/plugin-os' import pkg from '~/../package.json' const DEFAULT_TRAY_NAME = 'main' +/** + * macOS 上不给托盘图标设置悬停提示。 + * + * macOS 27 起,系统偶尔收不回 status item 的 tooltip 窗口:提示框会一直留在屏幕上, + * 鼠标移开也不消失,位置还可能漂到远离图标的地方,只有退出应用才消失。 + * 这是 AppKit 侧的回归(NSToolTipManager 收不到 mouseExited),与框架无关, + * 已有 AppKit / Qt / Chromium 多个应用的复现记录。 + * + * 规避办法是不写入 tooltip,托盘的标题与菜单更新保持不变。 + * macOS 27.2: NSStatusItem tooltip stays on screen + * https://developer.apple.com/forums/thread/856187 + * https://github.com/EasyTier/EasyTier/issues/2918 + */ +const supportsTrayTooltip = type() !== 'macos' + interface TrayMenuLabels { show: string quit: string @@ -35,7 +51,8 @@ export async function useTray(init: boolean = false) { tray = await TrayIcon.getById(DEFAULT_TRAY_NAME) if (!tray) { tray = await TrayIcon.new({ - tooltip: `EasyTier\n${pkg.version}`, + // Keep the title on macOS so the version stays reachable from the menu bar. + ...(supportsTrayTooltip ? { tooltip: `EasyTier\n${pkg.version}` } : {}), title: `EasyTier\n${pkg.version}`, id: DEFAULT_TRAY_NAME, menu: await Menu.new({ @@ -54,7 +71,8 @@ export async function useTray(init: boolean = false) { } if (init) { - tray.setTooltip(`EasyTier\n${pkg.version}`) + if (supportsTrayTooltip) + tray.setTooltip(`EasyTier\n${pkg.version}`) tray.setMenuOnLeftClick(false) tray.setMenu(await Menu.new({ id: 'main', @@ -130,7 +148,9 @@ export async function setTrayTooltip(tooltip: string) { const tray = await useTray() if (!tray) return - tray.setTooltip(text) + // macOS 上只更新标题,不写 tooltip(见 supportsTrayTooltip 的说明)。 + if (supportsTrayTooltip) + tray.setTooltip(text) tray.setTitle(text) } }