fix: handle macOS application reopen event to show main window#113
fix: handle macOS application reopen event to show main window#113zouyonghe merged 2 commits intoAstrBotDevs:mainfrom
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces logic to handle application reopen events on macOS, such as clicking the Dock icon. It adds a new ShowMainWindow action to the RunEventAction enum and implements a reopen_event_action helper to trigger this action when no windows are currently visible. Feedback indicates that the current implementation might be too restrictive; using has_visible_windows to guard the action could prevent the main window from appearing if only auxiliary windows (like settings) are open. It is suggested to ensure the main window is consistently focused or restored regardless of other visible windows.
| pub(crate) fn reopen_event_action(has_visible_windows: bool) -> RunEventAction { | ||
| if has_visible_windows { | ||
| RunEventAction::None | ||
| } else { | ||
| RunEventAction::ShowMainWindow | ||
| } | ||
| } |
There was a problem hiding this comment.
Pull request overview
This PR fixes macOS behavior where clicking the Dock icon after closing (hiding) the main window does not reopen/show the window, by mapping Tauri’s macOS RunEvent::Reopen into an internal runtime action and handling it in the desktop runtime event loop.
Changes:
- Add a new runtime semantic action
RunEventAction::ShowMainWindowto avoid leaking platform event names into higher-level logic. - Handle macOS
RunEvent::Reopen { has_visible_windows, .. }by showing the main window only when no windows are currently visible. - Add unit test coverage for the reopen decision logic (
reopen_event_action).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src-tauri/src/app_runtime.rs | Handles the new ShowMainWindow runtime action by calling window::actions::show_main_window. |
| src-tauri/src/app_runtime_events.rs | Introduces ShowMainWindow, adds macOS Reopen mapping, and adds unit tests for the reopen decision. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
把代码格式化一下就可以合了 |
动机/Motivation
AstrBotDevs/AstrBot#7336
issue 中提到的 Mac 下无法 Reopen 的问题,我在本地环境下也成功复现:
点击左上角红色关闭按钮后,主窗口被隐藏,但应用进程仍然常驻;此时再次点击 Dock
图标无法重新打开主窗口,只能通过顶部状态栏/托盘恢复。
Summary / 改动概述
ShowMainWindow语义,避免把平台事件名直接泄漏到业务层。RunEvent::Reopen { has_visible_windows, .. }增加处理:当应用当前没有可见窗口时,恢复主窗口显示。Quit仍然是真正退出应用。Verification / 验证方式
本地复现与验证流程:
———
Checklist / 检查清单
above). / 我已在本地验证并在上方提供日志/截图。
link. / 如果修改了工作流,我已附上至少一个相关 Actions 运行链接。
tauri/Cargo.lock, lockfiles under changed package dirs). / 如果引入或升级依
赖,已同步更新相关 lock 文件(如 src-tauri/Cargo.lock、对应包目录中的 lock
文件)。
Summary by Sourcery
Handle macOS application reopen events to restore the main window when no window is visible.
Bug Fixes:
Enhancements:
Tests: