Skip to content

fix(desktop): quit when the window close button is pressed - #9

Open
cabichahine wants to merge 1 commit into
Andarius:masterfrom
cabichahine:fix/macos-window-close
Open

fix(desktop): quit when the window close button is pressed#9
cabichahine wants to merge 1 commit into
Andarius:masterfrom
cabichahine:fix/macos-window-close

Conversation

@cabichahine

@cabichahine cabichahine commented Jul 29, 2026

Copy link
Copy Markdown

Fixes #10

Problem

On macOS, clicking the close button (top-left X) does nothing — the window stays on screen and the process keeps running.

Root cause

deno desktop emits a close event on the BrowserWindow when the native close button is pressed, but takes no default action of its own — it neither destroys the window nor terminates the process. src/deno/main.ts registered listeners for focus, resize and move, but not close, so the click was a no-op.

Verified against a minimal deno desktop app containing no BrowserWindow code at all — it reproduces identically, confirming this is runtime default behavior rather than something the window-adoption code introduced. Cmd+Q was never affected because it quits via the app menu, which is why the app was still closable.

Fix

Handle close explicitly: flush the pending geometry write, destroy the window, then exit.

Persisting on the close path also fixes a second bug — geometry was silently lost when the window was resized within 400ms of closing, because the debounced write never landed.

Window lifecycle moves into src/deno/window.ts with I/O injected so it can be unit tested; the geometry write is now synchronous so it completes before Deno.exit.

Verification

  • Real app, real click. Built the bundle and drove the native close button via System Events. Before: window remained, process alive. After: window closes, process exits, geometry persisted.
  • Debounce flush, same path: resized to 1100x700 and immediately clicked X — window.json recorded {"width":1100,"height":700,...} where it previously kept the stale size.
  • 8 new unit tests in tests/deno/window.test.ts. Mutation-checked: disabling the close listener fails 5 of them.
  • just ci green — 138 unit tests, 10 e2e, tsc --noEmit and deno check clean.

Note

Closing the window now quits the app, matching the Linux behavior. This is a deliberate choice over the macOS convention of keeping an app alive with no windows — this is a single-window utility with no dock-reopen handling, so staying alive windowless would leave it unreachable.

🤖 Generated with Claude Code

https://claude.ai/code/session_0117fevYXwnaG5Kr8MLX6YfQ

On macOS the top-left X did nothing: the window stayed on screen and the
process kept running.

`deno desktop` emits a `close` event on the BrowserWindow when the native
close button is pressed but takes no default action of its own — it neither
destroys the window nor terminates the process. main.ts listened for `focus`,
`resize` and `move` but not `close`, so the click was a no-op. Verified
against a minimal `deno desktop` app with no BrowserWindow code at all, which
reproduces identically. Cmd+Q was unaffected because it quits via the app menu.

Handle `close` explicitly: flush the pending geometry write, destroy the
window, then exit. Persisting on the close path also fixes geometry being
lost when the window was resized within 400ms of closing — the debounced
write never landed.

Window lifecycle moves to src/deno/window.ts with I/O injected so it is unit
testable; the geometry write is now synchronous so it completes before exit.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0117fevYXwnaG5Kr8MLX6YfQ
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.

macOS: window close button (top-left X) does nothing

1 participant