fix(macos): reopen main window when clicking dock icon after close - #24
Merged
Conversation
macOS 不会在最后一个窗口关闭后退出进程(预期),用户点 Dock 图标会触发 gpui 的 Platform::on_reopen。原代码没有注册这个回调,Dock 点击就变成静默的 no-op,只能 kill+重启 app 才能看到窗口。 把启动期的窗口配置抽成 open_main_window,然后在 Application 上注册 on_reopen:无窗时复用同一份配置重建,有窗则 activate(true) 把已有窗口拉到前台,避免重复实例。失败路径仍走 wake-core 的 show_fatal_alert,保持与原启动流程一致的错误处理。
iAmCorey
approved these changes
Sep 2, 2026
iAmCorey
left a comment
Owner
There was a problem hiding this comment.
实现方向正确,使用 GPUI Application::on_reopen 重建已关闭的主窗口,改动范围集中且未发现阻塞问题。已在独立 worktree 验证:cargo fmt --all -- --check、cargo check -p wake、cargo test -p wake(25 passed,0 failed,1 ignored)。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
macOS 不会在最后一个窗口关闭后退出 Wake 进程(预期行为,应用继续留在 Dock 中)。但是点击 Dock 图标本来应该把主窗口重新打开,原实现却没有任何响应——必须完全退出再重新启动 Wake 才能看到窗口。
原因
gpui 的
Platformtrait 提供了一个on_reopen回调(Application::on_reopen),对应 macOS 的applicationShouldHandleReopen:hasVisibleWindows:。原代码既没有注册这个回调,也没有在窗口被移除后重新打开窗口的逻辑,所以 Dock 图标点击变成了静默的 no-op。修复
把启动期构造主窗口的代码抽成
open_main_window(cx)辅助函数,然后在Application上注册on_reopen:cx.activate(true)把已存在的窗口拉到前台,避免重复创建实例开窗失败仍然走
wake-core::services::terminal::show_fatal_alert系统对话框,与原启动流程的错误处理一致。CloseWindow动作(cmd-W / File 菜单)保持原行为不变——只有 macOS 的 Dock 重开这条路径被接上。改动
crates/wake/src/main.rs:抽出open_main_window辅助函数 + 注册Application::on_reopen(+74 / −53)验证
on_reopen在这两平台是空操作,原行为不变 ✅show_fatal_alert并退出 ✅Problem
On macOS, closing the last Wake window does not terminate the process — that's expected, the app remains in the Dock. But clicking the Dock icon should bring the main window back, and the previous build silently ignored that gesture. Users had to fully quit and relaunch Wake to see a window again.
Root cause
gpui's
Platformtrait exposes anon_reopenhook (Application::on_reopen) that wires up to macOS'sapplicationShouldHandleReopen:hasVisibleWindows:. Wake never registered a handler and had no path to recreate a window afterWindow::remove_window()was called from the close button, so the Dock click became a silent no-op.Fix
Extract the launch-time window setup into
open_main_window(cx)and registerApplication::on_reopen:cx.activate(true)to bring the existing window forward — no duplicate Workbench instanceWindow creation failures still fall through to
wake-core::services::terminal::show_fatal_alert+process::exit(1), matching the startup error path. The existingCloseWindowaction (cmd-W / File menu) keeps its currentremove_window()semantics — only the Dock-reopen path gets new behavior.Changes
crates/wake/src/main.rs: extractedopen_main_windowhelper + registeredApplication::on_reopen(+74 / −53)Verification
on_reopenis a no-op on these platforms, behavior unchanged ✅show_fatal_alertand exits ✅