Skip to content

fix(macos): reopen main window when clicking dock icon after close - #24

Merged
iAmCorey merged 1 commit into
iAmCorey:mainfrom
MiQieR:fix/macos-dock-reopen
Sep 2, 2026
Merged

fix(macos): reopen main window when clicking dock icon after close#24
iAmCorey merged 1 commit into
iAmCorey:mainfrom
MiQieR:fix/macos-dock-reopen

Conversation

@MiQieR

@MiQieR MiQieR commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

验证:v0.3.5Test macOS 安装包本地手测通过,Dock 图标点击行为已恢复。


问题

macOS 不会在最后一个窗口关闭后退出 Wake 进程(预期行为,应用继续留在 Dock 中)。但是点击 Dock 图标本来应该把主窗口重新打开,原实现却没有任何响应——必须完全退出再重新启动 Wake 才能看到窗口。

原因

gpui 的 Platform trait 提供了一个 on_reopen 回调(Application::on_reopen),对应 macOS 的 applicationShouldHandleReopen:hasVisibleWindows:。原代码既没有注册这个回调,也没有在窗口被移除后重新打开窗口的逻辑,所以 Dock 图标点击变成了静默的 no-op。

修复

把启动期构造主窗口的代码抽成 open_main_window(cx) 辅助函数,然后在 Application 上注册 on_reopen

  • 没有窗口时(用户关了红钮、Dock 图标再次点击):复用同一份配置重建主窗口
  • 有窗口时(窗口最小化、多实例切换):只调用 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)
  • 仅影响主进程入口,不修改 workbench、settings、wake-core 等任何下游模块

验证

  • 已通过 v0.3.5Test macOS 安装包本地手测
  • 行为契约:
    • macOS:红钮关窗 → Dock 点击 → 主窗口重现 ✅
    • macOS:窗口最小化 → Dock 点击 → 窗口恢复并聚焦 ✅
    • macOS:app 已隐藏(cmd-H)→ Dock 点击 → 窗口恢复并聚焦 ✅
    • Linux/Windows:on_reopen 在这两平台是空操作,原行为不变 ✅
    • 启动失败(GPU/RDP 会话等)依然弹 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 Platform trait exposes an on_reopen hook (Application::on_reopen) that wires up to macOS's applicationShouldHandleReopen:hasVisibleWindows:. Wake never registered a handler and had no path to recreate a window after Window::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 register Application::on_reopen:

  • No windows (user closed the red button, then clicked the Dock): reuse the exact same config to recreate the main window
  • Windows exist (window minimized, or jumping between instances): just call cx.activate(true) to bring the existing window forward — no duplicate Workbench instance

Window creation failures still fall through to wake-core::services::terminal::show_fatal_alert + process::exit(1), matching the startup error path. The existing CloseWindow action (cmd-W / File menu) keeps its current remove_window() semantics — only the Dock-reopen path gets new behavior.

Changes

  • crates/wake/src/main.rs: extracted open_main_window helper + registered Application::on_reopen (+74 / −53)
  • Only touches the process entry point — no changes to workbench, settings, wake-core, or any downstream module

Verification

  • Manually verified on macOS via the v0.3.5Test installer built by the existing GitHub Action
  • Behavioral contract:
    • macOS: red button close → Dock click → main window returns ✅
    • macOS: window minimized → Dock click → window restored and focused ✅
    • macOS: app hidden (cmd-H) → Dock click → window restored and focused ✅
    • Linux/Windows: on_reopen is a no-op on these platforms, behavior unchanged ✅
    • Startup failure (GPU / RDP session) still shows show_fatal_alert and exits ✅

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 iAmCorey left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

实现方向正确,使用 GPUI Application::on_reopen 重建已关闭的主窗口,改动范围集中且未发现阻塞问题。已在独立 worktree 验证:cargo fmt --all -- --check、cargo check -p wake、cargo test -p wake(25 passed,0 failed,1 ignored)。

@iAmCorey
iAmCorey merged commit 4e74cb3 into iAmCorey:main Sep 2, 2026
@MiQieR
MiQieR deleted the fix/macos-dock-reopen branch September 3, 2026 15:05
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