Skip to content

fix(tray): 支持左键单击托盘图标打开主面板 - #21

Merged
sunerpy merged 2 commits into
mainfrom
fix/tray-icon-click
Aug 11, 2026
Merged

fix(tray): 支持左键单击托盘图标打开主面板#21
sunerpy merged 2 commits into
mainfrom
fix/tray-icon-click

Conversation

@sunerpy

@sunerpy sunerpy commented Aug 11, 2026

Copy link
Copy Markdown
Owner

变化

此前 TrayIconBuilder 只注册了 .on_menu_event没有 .on_tray_icon_event,所以点击托盘图标本身毫无反应——用户必须「右键出菜单 → 点『打开 AgentLens』」两步才能打开面板。

本次补上图标点击路径,用户可感知的变化是:单击或双击托盘图标都能直接打开主面板(双击天然经第一次点击生效)。

show_main_windowshow + unminimize + set_focus,幂等)本就存在,只是此前没有任何点击路径调用它。

实现要点

  • TrayIconBuilder 注册 .on_tray_icon_event
  • 新增纯函数 tray_click_action(button, button_state),仅在 (Left, Down) 返回 Open
    —— Tauri 在按下与释放各派发一次 Click,两个都响应会开两次窗口
  • 不显式处理 DoubleClick:Windows 双击序列先派发一次 Click,双击经第一次点击生效
  • 新增单测 one_left_tray_click_dispatches_open_exactly_once,把「一次物理点击只派发一次」钉住
  • 注释说明 Linux AppIndicator 不派发托盘图标事件,右键菜单的「打开 AgentLens」是该平台回退路径

门禁结果(均已在本地跑通)

检查 结果
cargo test --workspace 427 passed / 0 failed / 21 ignored(基线 426,新增 1 条)
cargo clippy --workspace --all-targets -- -D warnings exit 0
cargo fmt --all -- --check exit 0
make coverage-gate exit 0,行覆盖率 92.51%(25238/27281),门槛 90%
cargo xwin check -p agentlens-tauri --tests --target x86_64-pc-windows-msvc exit 0
lsp_diagnostics src-tauri/src/tray.rs No diagnostics found

影响面

src-tauri/src/tray.rs(+53/-1),无接口、数据模型或配置变更。

- TrayIconBuilder 注册 on_tray_icon_event,此前只有 on_menu_event,
  点击图标本身没有任何回调,用户必须右键出菜单再点「打开 AgentLens」两步才能开面板
- 新增纯函数 tray_click_action,仅在 (Left, Down) 返回 Open;
  Tauri 在按下与释放各派发一次 Click,两者都响应会开两次窗口
- 不显式处理 DoubleClick:Windows 双击序列先派发一次 Click,双击天然经第一次点击生效
- 补单测 one_left_tray_click_dispatches_open_exactly_once,钉住一次物理点击只派发一次
- 注释说明 Linux AppIndicator 不派发托盘图标事件,右键菜单项是该平台回退路径
@codecov

codecov Bot commented Aug 11, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.56604% with 5 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src-tauri/src/tray.rs 90.56% 5 Missing ⚠️
Files with missing lines Coverage Δ
src-tauri/src/tray.rs 81.91% <90.56%> (+0.74%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

- 新增 tray_icon_event_action,从 TrayIconEvent 解构出按钮与状态后委托给
  tray_click_action;闭包退化成三行适配器,只负责取 action 并在 Open 时开窗
- 原先解构写在闭包内,而闭包只有原生托盘派发才执行,MockRuntime 注入不到,
  九行插桩行全部未覆盖,补丁覆盖率仅 64.0%,低于 90% 门槛
- 新增 real_tray_events_open_once_and_ignore_windows_double_click_replay,
  用真实构造的 Click/DoubleClick 断言仅 (Left,Down) 开窗,其余一律忽略
- 行为零变化,仅提升可测性;补丁覆盖率升至 90.6%,行覆盖率 92.53%
@sunerpy
sunerpy merged commit b9fff30 into main Aug 11, 2026
7 checks passed
@sunerpy
sunerpy deleted the fix/tray-icon-click branch August 11, 2026 15:03
sunerpy pushed a commit that referenced this pull request Aug 11, 2026
本 PR 由 release-please 维护:合并后 .github/workflows/release.yml 会自己建 tag 与
draft Release,三平台产物齐全才公开。
---


<details><summary>0.0.3</summary>

## [0.0.3](v0.0.2...v0.0.3)
(2026-08-11)


### Bug Fixes

* **tray:** 支持左键单击托盘图标打开主面板
([#21](#21))
([b9fff30](b9fff30))


### Documentation

* **readme:** 重写语感并同步 Cargo.lock 到 0.0.2 版本号
([#19](#19))
([c6d5ad9](c6d5ad9))


### Build System

* **release-please:** 把 Cargo.lock 纳入发版版本号同步
([#22](#22))
([fd028fe](fd028fe))
</details>

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant