fix(tray): stabilize Windows right-click tray menu behavior#362
Conversation
There was a problem hiding this comment.
Pull request overview
This PR targets the Tauri desktop tray logic to stabilize Windows 11 right-click tray menu behavior by changing when the tray menu is refreshed in response to tray click events.
Changes:
- Refactors the right-click refresh condition into a helper (
should_refresh_tray_menu_on_click_event) used by the tray event handler. - Adds unit tests covering the right-click button/state filtering logic.
- Introduces platform-conditional behavior for deciding whether/when to refresh (but the current Windows branch disables refresh entirely, which conflicts with the PR description and intended fix).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
审查结论:当前不能合并。 Windows 分支中的 should_refresh_tray_menu_on_click_event 对所有托盘点击都固定返回 false,而 refresh_tray_menu 目前只从这个点击判断调用。这样“5 小时重置 / 7 天重置”菜单内容只会在 setup_tray 启动构建时读取一次,Windows 用户之后看到的重置时间会一直停留在旧值,直到重启应用。 当前测试还把 Windows 的 Right Down 和 Right Up 都“不刷新”固化成了预期,与 PR 描述中“Windows 在右键 Down 时刷新”的说法不一致。 请在避免 Windows 右键菜单回归的同时补一个可靠的数据刷新触发点,例如在 usage 更新事件中重建菜单,或采用不会发生 click-time 菜单替换问题的刷新机制;并补充“用量数据变化后托盘文案会更新”的回归测试。 |
已根据意见进行代码修改。抱歉本人基本不会Rust代码,希望你能代为测试。谢谢! |
变更摘要
Up阶段刷新菜单触发set_menu,与系统菜单弹出时序冲突导致菜单被立即收起。Down,其他平台保持Up),不改动现有命令链、菜单项处理和窗口生命周期主逻辑。目前在Windows端下右键菜单可以正常显示:
Fix #356
改动范围
主要文件
apps/src-tauri/src/app_shell/tray.rsshould_refresh_tray_menu_on_click_eventtray_menu_refresh_trigger_state验证
pnpm -C apps run testpnpm -C apps run buildpnpm -C apps run test:uicargo test --workspace已执行的实际验证:
未执行的验证与原因:
风险与影响面
Up触发路径,代码层面避免平台副作用扩散。备注