Skip to content

feat: optimize macOS application lifecycle and window management#29

Open
kckylechen1 wants to merge 1 commit intoLampese:mainfrom
kckylechen1:feat/macos-reopen-window
Open

feat: optimize macOS application lifecycle and window management#29
kckylechen1 wants to merge 1 commit intoLampese:mainfrom
kckylechen1:feat/macos-reopen-window

Conversation

@kckylechen1
Copy link
Copy Markdown

@kckylechen1 kckylechen1 commented Mar 25, 2026

PR简介

优化 macOS 应用程序的生命周期和窗口管理,使其符合原生菜单栏工具(Menu Bar Utility)的行为(类似 Antigravity Manager)。

  • 托盘图标支持 :使用 Tauri 的 tray-icon 功能添加了原生菜单栏图标。
  • 改进关闭行为 :
    • 点击窗口关闭按钮现在会隐藏窗口和 Dock 图标,而不是退出程序或保留 Dock 占位。
    • 应用程序在后台保持运行,可通过托盘图标访问。
  • 重开逻辑 :
    • 左键点击托盘图标可恢复并聚焦主窗口。
    • 从 Dock(如果已固定)或 Spotlight 重新打开应用时,也会恢复主窗口并临时显示 Dock 图标。
  • 托盘菜单 :为托盘图标添加了右键菜单,包含:
    • Open Codex Switcher : 显示主窗口。
    • Quit : 完全退出应用程序。
  • 生命周期管理 :
    • 仅在主窗口关闭时隐藏 Dock 图标,确保用户在主动使用时有明确的视觉反馈。
    • 处理了 RunEvent::Reopen 事件,确保窗口恢复逻辑稳健。 Technical Implementation
  • 修改了 lib.rs 以处理 WindowEvent::CloseRequested 和 RunEvent::Reopen 。
  • 集成了 tauri::tray::TrayIconBuilder 实现菜单栏支持。
  • 在 tauri.conf.json 中启用了 tray-icon 特性。 Verification
  • pnpm build 通过
  • cargo check 通过
  • pnpm tauri build --bundles app 成功产出 .app
  • macOS 实机验证:启动显示 Dock -> 点击关闭隐藏 Dock -> 托盘重开窗口。

Summary

Improve macOS window lifecycle to behave like a native tray utility.

Changes

  • Add tray icon support and tray menu actions (Open Codex Switcher, Quit).
  • Intercept window close to hide window instead of exiting.
  • Hide Dock icon only after close so first launch remains visible in Dock.
  • Restore and focus main window when reopening from tray or app reopen event.
  • Keep runtime-based Dock control instead of permanent menu-bar-only mode.

Verification

  • pnpm build
  • cargo check --manifest-path src-tauri/Cargo.toml
  • pnpm tauri build --bundles app
  • Manual macOS check: launch shows Dock; close hides Dock and keeps tray; tray click reopens window.

- Implement tray icon with click-to-reopen functionality
- Hide Dock icon only after the main window is closed
- Add 'Open Codex Switcher' and 'Quit' items to the tray menu
- Ensure the application remains accessible from the menu bar
Copy link
Copy Markdown
Owner

@Lampese Lampese left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requesting changes for two behavioral issues:

  1. The close interception is not scoped to macOS. WindowEvent::CloseRequested is now prevented for all platforms, and the window is hidden unconditionally. Only the Dock visibility call is macOS-specific. That means Windows and Linux users also get a new "hide to tray" close behavior even though the PR is framed as a macOS lifecycle optimization.

  2. The PR description says reopening should temporarily restore the Dock icon on macOS, but that behavior is not actually implemented. The code hides the Dock on close via set_dock_visibility(false), yet neither show_main_window() nor the RunEvent::Reopen path turns Dock visibility back on. So the implemented behavior does not match the stated reopen flow.

I think both issues should be resolved before merging. If this is meant to be a macOS-specific lifecycle adjustment, the close interception should be scoped accordingly, and the Dock visibility restore path needs to be explicit.

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.

2 participants