Skip to content

Closing the desktop app's window keeps it running, as the Mac app does - #240

Merged
pitis merged 5 commits into
mainfrom
feat/desktop-keep-running
Nov 28, 2026
Merged

pitis merged 5 commits into
mainfrom
feat/desktop-keep-running

Conversation

@pitis

@pitis pitis commented Nov 28, 2026 •

Copy link
Copy Markdown
Owner

What changed

The desktop app now does what the Mac app does when its window closes (owner's call on #228: match the Mac).

  • Closing the window keeps Hush running. The close button (and Close Window, once it exists: it takes the same path) only takes the window out of sight while the core is open. On macOS the app hides, and its Dock icon brings it back. On Windows and Linux the window minimizes (see the shortcut below). Notifications keep coming and the unread count keeps counting, because nothing is torn down. Messages aren't marked read while it's out of sight: that needs the window active and visible, and a hidden or minimized window is neither. A recording playing and an open view-once look stop when the window closes: in the Mac app they belong to the window's views. If the core isn't open (not yet, or it couldn't open: nothing is running), closing still closes the window and quits.
  • Bringing it back. The tray's Open Hush, a notification click, the Dock icon (macOS) or launching Hush again. They share one running::show, which on macOS also unhides the app, since activating an app isn't documented to undo hiding it. With the tray hidden on Windows and Linux, launching again is the way back (the owner's accepted rule).
  • One Hush at a time. Once its core has opened the data, Hush listens on a loopback port and writes that port, with a random token, to running in its data folder. It removes the file when it quits. A later launch reads the file, sends the token, and if the running Hush answers, it brings up that Hush's window and exits before opening a window of its own. The running Hush only answers its own token, so a port it left behind after a crash, later taken by another program or by another user's Hush, is never mistaken for it. A launch refused the data (two started at once) never takes the file from the Hush that has it. A refused connection gives up after 250 ms. A launch that can't reach the running Hush now says "Hush is already running." (the Mac app's words) instead of "couldn't open the data: the data is already open…".
  • Quitting from the Dock or at logout. GPUI's own quit (the Dock's Quit and logout on macOS, WM_ENDSESSION on Windows) used to skip the orderly stop. It now runs the same stop as ⌘Q / Ctrl+Q and the tray's Quit: the drafts are written, then the core stops. GPUI waits only 200 ms for this, and it blocks the main thread while it waits. So the draft writer now runs on a background thread (a task on the main thread could never finish there). Its failures are logged where they happen and still reach the window.
  • Windows and Linux quit only through app::quit (QuitMode::Explicit). GPUI's default there quits as soon as the last window closes, which cut the orderly quit short.

⌘Q / Ctrl+Q and the tray's Quit work as before.

What remains (as far as each OS allows)

  • Dock's Quit and logout: within GPUI's 200 ms the drafts get written (one fast write per chat at most). The core may not finish stopping in that time. The Mac app waits up to 6 s with .terminateLater, which GPUI doesn't offer.
  • shortcut: Linux logout: GPUI catches no signal, so Hush is ended without running the stop (the last draft and a clean stop are lost there). To fix it: catch SIGTERM and call quit.
  • A launch while Hush is quitting (during its stop, up to 5 s) finds no running file and shows "Hush is already running." until the old core has stopped.
  • shortcut: On Windows and Linux the window minimizes rather than hides, so the taskbar keeps its button. GPUI can't hide a window, and Wayland has no hidden windows. A tiling window manager that ignores minimizing leaves the window where it is. To hide it instead: ShowWindow(SW_HIDE) on Windows, unmapping on X11.
  • The OS's focus rules (Windows, Wayland) may only let a second launch or the tray make the window ask for attention, not come to the front.

How it was tested

New tests in app/running.rs. Each of the first five failed with its behaviour taken out, then passed:

  • a_later_launch_brings_up_the_running_hush: a launch reaches the listener and is answered, twice.
  • a_launch_that_cant_reach_the_running_hush_says_it_runs: before, the message was "couldn't open the data: …".
  • closing_the_window_keeps_hush_running_once_its_core_is_open (window test): without a core the window closes; with one it stays, its view-once look ends, and show brings it up (active).
  • a_later_launch_brings_up_the_window_once_this_hush_has_the_data (window test): no running file until this Hush's core is open; then a launch brings the window up, twice.
  • quitting_from_the_dock_or_at_logout_keeps_the_draft_and_stops_the_core (window test): after GPUI's own quit, the data opens again with the draft typed just before. Before, the core was still holding the data. Also checks the running file is gone after the quit.
  • only_the_hush_that_wrote_the_folder_is_taken_for_running: a port taken by another Hush with another token, a dead port, or a garbled file all read as "not running".

What the tests can't show: that stop waits for the drafts. The test context runs the draft write before the quit starts; drafts.rs's existing writer test covers the wait. Also: GPUI's test scheduler runs every task while it waits, so it can't reproduce the main thread being blocked during GPUI's quit. The background draft writer is based on reading GPUI's PlatformScheduler::block, which polls only the quit future.

Gate (from core/):

  • cargo fmt --check: pass
  • cargo clippy --all-targets -q -- -D warnings: pass
  • cargo clippy --all-targets --features hush-desktop/snapshot -q -- -D warnings: pass
  • cargo test --features hush-desktop/snapshot -q: pass (301 desktop, 537 core), run on the head merged with the latest main

Swift leg (xcodebuild) not run: nothing in app/ changed. Snapshots: --snapshot still renders every demo screen. The change draws nothing new; the only new text is the failed-start screen's message, which has no demo screen. Not run on Windows or Linux: there's no machine for them here.

Closes #228

Closing the window hides it while the core is open (the app hides on macOS,
the window minimizes elsewhere); the tray's Open Hush, a notification, the
Dock icon or a second launch bring it back. A second launch finds the running
copy through a loopback port and token in the data folder, asks it to show
its window, and ends; one that can't reach it says "Hush is already running."

GPUI's own quit (the Dock's Quit, logging out) now writes the drafts and stops
the core within the 200 ms GPUI gives it: the draft writer runs off the main
thread, which that quit blocks. Windows and Linux quit only through the
orderly quit, not as the window closes.
…s them at quit

A launch refused the data (two at once) no longer takes the running file from
the Hush that has it: listening starts once the core opened. Quitting removes
the file, so later launches don't wait on a closed port. A draft write that
fails while GPUI's quit blocks the main thread is logged where it fails.
Comments corrected: Linux's logout, the system's close, quit modes.
A recording playing (or about to) stops and a view-once look ends when the
window closes, as they go with the Mac app's window. A launch gives a refused
loopback connection 250 ms, not the seconds Windows retries it.
@pitis

pitis commented Nov 28, 2026

Copy link
Copy Markdown
Owner Author

Review (pr-review-toolkit: code, silent failures, tests, comments)

Nothing Critical. Fixes are in 1db548f and 902e52f. The branch is merged with the latest main, and the gate passes on that head (fmt, both clippy legs, cargo test --features hush-desktop/snapshot).

Important: fixed

  1. A launch refused the data took the running file (raised by all four reviewers). When two launches overlapped, the one that lost the data lock could write the file last. Launching again would then show its "Hush is already running." for the rest of the real Hush's life.
    • Fix: listening starts only once this Hush's core has opened (observe_global::<Core>, once).
    • Test: a_later_launch_brings_up_the_window_once_this_hush_has_the_data, which fails if listening starts at once.
  2. A draft write failing during GPUI's quit was never logged. The warn ran in a foreground task, which can't run while GPUI blocks the main thread. Fix: the warn now runs in the background writer; only the message for the window goes across.
  3. Every launch after a clean quit dialed a dead port, which on Windows can take seconds to be refused. Fix: stop removes the file first thing, and the connect gives up after 250 ms (reading the answer still has 2 s). Test: the quit test checks the file is gone.
  4. Closing the window left a recording playing, with no window to stop it from. In the Mac app the player goes with the window's view. Fix: closing stops playback, and also ends a view-once look the same way. Test: the close test, over a view-once look, checks it ended.
  5. Nothing tested that a later launch brings the window up. Fixed by the new launch test in item 1, which fails if show isn't called.
  6. Inaccurate comments:
    • Linux logout isn't caught: now a shortcut: comment.
    • The close path is the system's close (a Close Window of our own must go through it, not remove_window).
    • QuitMode only governs the last window closing.
    • start's doc no longer promises the core stops within 200 ms.
    • "for quit" → "for stop".
    • "shown" means answered, not drawn.
    • The listener's break comment.

Declined

  • Harden the Dock-quit test so it proves stop waits for the drafts. I tried it: the test context runs the write before the quit starts, so the test still passes without the wait. drafts.rs's writer test covers the wait.
  • Reword "Hush is already running." These are the Mac app's words (AppStore.swift), kept for parity.
  • Close a failed screen instead of hiding it when a core is open. The Mac app keeps running whenever its window closes; ⌘Q/Ctrl+Q and the tray's Quit still quit.
  • .expect when registering the close handler. It can't fail on the window just opened, and a panic at launch would be worse than a close that quits.
  • Throttle the listener on accept errors, and serve launches concurrently. Only a local process misbehaving on purpose, or a process out of file descriptors, would hit these. The worst case is one launch that shows "already running".
  • Test that a failed draft write reaches the window. There's no cheap way to make set_draft fail after the drafts were read; the reporting is a direct channel.

For the owner (not changed)

  • Dock's Quit and logout get GPUI's 200 ms. That's enough for the drafts, maybe not for the core to stop. The Mac app's .terminateLater (up to 6 s) would need a method added to GPUI's app delegate at runtime.
  • A launch during Hush's own quit (its stop, up to 5 s) shows "Hush is already running." It could instead retry opening the data for a few seconds.
  • The OS's focus rules may leave a window raised from the tray or a second launch only asking for attention (Windows, Wayland: the launch's activation token isn't passed along). Not checked on a real Windows or Linux machine.

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.

Closing the desktop app's window keeps it running, as the Mac app does

1 participant