Skip to content

On macOS the desktop app opens the Mac app's data, linked, with its drafts and settings - #266

Merged
pitis merged 5 commits into
mainfrom
feat/take-over-mac-data
Nov 29, 2026
Merged

pitis merged 5 commits into
mainfrom
feat/take-over-mac-data

Conversation

@pitis

@pitis pitis commented Nov 29, 2026 •

Copy link
Copy Markdown
Owner

Hush is one app now (the owner's decision of 2026-11-29): on macOS the GPUI app opens the Mac app's own data folder and key, so its linked device, chats and drafts carry over without relinking.

What changed

  • Data folder (core/desktop/src/app/home.rs, new): "Hush" in the OS's local app data folder on every system (was "Hush Desktop"). On macOS that is ~/Library/Application Support/Hush, the Mac app's AppStore.dataDirectory, opened as it is. It is settled once per launch, at the first app::folder() (which main calls before any window).
  • Old "Hush Desktop" folder: moved to "Hush" once, only while no "Hush" folder exists, never merged. The order is the one that can't lose data. First it checks the old folder's .lock: if an older copy is running, it stops and says so. Then it copies the key to the new name, renames the folder, and only then removes the old key. If any step before the move fails, the old folder stays where it was, no new "Hush" folder is made (not even for an imported setting), and the window shows the reason with "Nothing was moved: open Hush again to try again." ("Hush couldn't start"). A "Hush" folder that can't be looked at counts as there. When "Hush" already exists, the old folder and key are left alone, and every launch says so in the log and in the Core Log once the core is open.
  • Key (key.rs): dev.pitis.hush/db-key (was dev.pitis.hush.desktop), i.e. the Mac app's Keychain.swift item in the login keychain (keyring's macOS store is the login keychain). copy_old/forget_old move the old one with its folder. The new name overwrites any key already under it, because without its folder that key opens nothing.
  • Mac app's settings (settings::adopt_mac, macOS only): appearance, notifications.content and menuBar.show from its user defaults (domain dev.pitis.hush, read through cfprefsd with NSUserDefaults.persistentDomainForName). Each one fills a setting this app hasn't saved yet, so each is taken once. Unknown values are skipped. The Mac app's user defaults are never written. The words match the Mac app's raw values, so the files keep them as they are.
  • Identity: APP_ID dev.pitis.HushDesktop → dev.pitis.hush. That is the Windows AUMID, the Linux app id and launcher name, the tray id, the LaunchAgent label and file name, and the autostart file name (the Linux launcher's D-Bus path follows). The Windows Run value "Hush Desktop" → "Hush". The device name the phone shows for new links is "Hush" (the Mac app's deviceName). A login item under the old name moves to Hush's name as it was, so the copy of Hush it opens doesn't change (login::replace_old). The new one is written first, then the old one is removed. On macOS the LaunchAgent's label is renamed; on Linux the autostart file is renamed. On Windows the Run value is copied unless it was switched off in Startup settings, then the old Run and StartupApproved values are removed.
  • "Hush is already running." now reads "Hush is already running: quit it, then open Hush again.", because on macOS the Mac app holding the data is now the likely cause, and a launch can't bring it up.
  • CLAUDE.md's stack rule now says the desktop app's folder and key are Hush's own, the former Swift app's on macOS, and that renaming either orphans the data. (The README's desktop paragraph that said otherwise went with Hush is the Rust core and the GPUI app: the Swift Mac app and its build are gone #265.)
  • HUSH_DATA_DIR (the owner's decision on this PR), for development and testing only. When it is set and not empty, the app uses that folder instead, and keeps the key in dev-key (0600) inside it, made on first use. It never asks the keychain, and it skips the "Hush Desktop" move, the login item replacement and the Mac app's settings import (home::settle, key::file_key). The README and CLAUDE.md say the key sits next to the data. CLAUDE.md also says that agents and scripts that launch the app must set it to a throwaway folder. scripts/perf.sh keeps measuring the owner's linked data (a throwaway folder isn't linked, and its launch ends at the chat list); a caller's own HUSH_DATA_DIR is used as set. When both "Hush" and "Hush Desktop" exist, "Hush" wins, as built (owner's decision).
  • objc2-foundation (already a direct macOS dependency) gains the NSUserDefaults, NSDictionary and NSValue features. Cargo.lock is unchanged.

Dropped from the issue

  • Drafts import: not a gap. The Mac app keeps drafts in the core's database (client.setDraft/drafts(), AppStore.saveDraft), the same store and keys (chat id) the desktop app reads (drafts.rs). They open with the folder. UserDefaults only holds draft.<chat id> keys from versions before drafts moved into the core. The Mac app moves those into the core and removes them at every launch, so none are left in practice.

Known limits

  • On macOS this unsigned, unbundled binary reads the Mac app's key with the keychain's "allow access" prompt. "Always Allow" trusts this build's code hash, so each rebuild asks again until the app ships with a stable signature.
  • A warning from the take-over itself (a login item that couldn't be replaced, an old key not removed) is lost. The core's log starts only when Client::open runs (sig_core::logging is private), as it already is for settings read at launch. The "left alone" note is logged after the core opens, so it shows.
  • On Windows, the AUMID registry key under the old id (Software\Classes\AppUserModelId\dev.pitis.HushDesktop) stays behind. It is a name only: the old app clears its toasts when it quits.

Switching on the owner's Mac (once)

  1. Build the GPUI app from current main (make desktop), so its core is at least as new as the Mac app's database.
  2. In the Swift Hush app: turn off Settings ▸ Open at login if it's on (its login item isn't carried over), then quit it (⌘Q; closing the window keeps it running). While it runs, the GPUI app can't open the data and says "Hush is already running."
  3. Open the GPUI app (make run). macOS asks once whether hush may use "dev.pitis.hush" in the keychain: enter the login password and choose Always Allow (Deny changes nothing; it asks again next launch). It opens linked, with chats, drafts, appearance, notification content and the menu bar choice.
  4. Turn on Open at login in the GPUI app's Settings if wanted.
  5. Delete the old Hush.app (and unregister stray copies with lsregister -u). Don't use its Unlink: that would unlink the shared device and delete the data.
  6. Optional: a ~/Library/Application Support/Hush Desktop folder and a dev.pitis.hush.desktop keychain item from earlier GPUI runs are left alone. Delete them by hand if they're not needed.

How it was tested

  • Test-first. These failed against stubs before the code went in (8 of the new tests; the other new ones check that nothing changes):
    • home::tests (temp local folders, key steps as closures). The Mac app's folder opens as is and an old one beside it is left alone. A computer with neither gets "Hush" and nothing is made early. The old folder moves with its key once (key copied before the rename, old key removed after). It stays put while its key doesn't copy, and while an older copy holds its .lock.
    • key::tests (keyring's mock store). The old key is copied over any key under the new name and kept until removed. Without an old key, nothing is copied. An old key that can't be read stops the move.
    • settings::tests. The Mac app's choices are taken once and settings saved here win. Unknown or missing values leave the defaults. Through cfprefsd, in a made-up domain (dev.pitis.hush.tests.desktop-defaults, written with /usr/bin/defaults, deleted after, file removed), a text reads as itself and a Bool as false.
    • login::tests: an entry under the old name moves to Hush's as it was, and with none there, nothing is written.
  • HUSH_DATA_DIR (these failed first against stubs): with it set, the folder and a key in a file there are used, and the keychain and this computer's folders aren't asked (a fake keychain and a folder step that fail the test if called). Without it, or empty, Hush's own folder and the keychain's key are used. The key file is made once (0600), kept, and made anew after it's forgotten; a key file that doesn't hold a key is never replaced.
  • After review: a refused rename keeps both folders and the old key; a key that can't be written under Hush's name stops the move; the key names are pinned to Keychain.swift's; the "never merged" checks compare exact contents.
  • The real folder, key and user defaults are only computed, never touched: app::folder() runs only from main, and no test calls it.
  • 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 (desktop 363, core 541).
  • Windows code in login.rs: type-checked and clippy-clean (-D warnings) for x86_64-pc-windows-msvc in a scratch crate that includes the file as is. It was not built in the workspace (no cross C toolchain for the core).
  • Merged with main after Hush is the Rust core and the GPUI app: the Swift Mac app and its build are gone #265 (the Swift app removed); the gate above was run again on the merged head (desktop 363, core 541: pass). No snapshots: nothing on screen changes (a failed move uses the existing "Hush couldn't start" screen). The app wasn't run against the real data, by design.

Closes #263

Hush is one app now: the GPUI app's data folder is "Hush" and its key
dev.pitis.hush/db-key on every system, which on macOS are the Mac app's own,
so its linked device, chats and drafts open as they are. Its appearance,
notification content and menu bar choices are taken once from its user
defaults. A "Hush Desktop" folder and key from earlier runs move to the new
names once, while there is no "Hush" folder, and are otherwise left alone.
The app id, login item, Run value and device name become Hush's; an old login
item is replaced.
…s an old login item's program

- The Mac app's choices are taken inside the take-over, after the move, so a
  failed move makes no folder (and the import is used on every system).
- A Hush folder that can't be looked at counts as there; a lock that can't be
  taken for another reason than an older copy says so; a move a launch at the
  same time made counts as done; failures say nothing was moved.
- An old login item moves to Hush's name as it was, the copy it opens too.
- An old Hush Desktop folder left alone is noted in the Core Log too.
- "Hush is already running" says to quit it (on macOS maybe the Mac app).
- menuBar.show takes only a Bool; the defaults test uses a domain of its own
  per run and tolerates cfprefsd removing its file.
- Tests: exact contents (never merged), a refused rename, a key that can't be
  written, the key names, the login item's carry-over.
- Docs: README, CLAUDE.md rule, key and home comments.
@pitis

pitis commented Nov 29, 2026

Copy link
Copy Markdown
Owner Author

Review (/pr-review-toolkit:review-pr: code, errors, tests, comments)

There were no Critical findings. Fixes are in fd491f7. The gate was run again: fmt, both clippy runs and cargo test --features hush-desktop/snapshot (desktop 359, core 541) all pass. The Windows login.rs was type-checked and is clippy-clean for x86_64-pc-windows-msvc.

Important: fixed

  1. The import was dead code on Linux and Windows. adopt_mac/adopt were called only on macOS, so -D warnings would fail on those systems. The import now runs inside take_over, after the move, on every system; off macOS it reads nothing (|_| None).
  2. "Hush is already running." gave no way out when the Mac app holds the data, and a launch can't bring that app up. The message is now "Hush is already running: quit it, then open Hush again." The running.rs test was updated.
  3. A "Hush Desktop" folder left alone was noted only in the system log. It is now also kept in the Core Log when the core opens (home::left_alone → core_log).
  4. The "never merged" test couldn't see an overwrite. It now compares exact contents, and the old folder has a file of its own that must not appear in "Hush".
  5. A refused rename had no test. Added a_move_refused_keeps_both_folders_and_the_old_key: "Hush" appears while the key is copied, the move fails with "Nothing was moved", and both folders and the old key stay.
  6. A key that can't be written under Hush's name had no test. Added an_old_key_that_cant_be_kept_under_hushs_name_stops_the_move.
  7. "No new folder while an old one waits" wasn't covered above the move. The import now sits inside take_over, after the move. The tests for a locked old folder and a refused key now pass Mac app choices too, and check that no "Hush" folder is made.
  8. The key names that must match Keychain.swift weren't pinned. Added the_names_are_the_mac_apps_and_the_old_ones.
  9. The defaults test shared one domain across runs. It now uses its own domain per process, and a file cfprefsd already removed is fine.
  10. The guard that writes a new login item only when an old one exists had no test. The check moved into replace and is tested: with no old item, nothing is written.
  11. Comments:
    • The README desktop paragraph was stale; it is updated.
    • The take-over's warnings, which come before the core's log is up, now carry a shortcut: comment.
    • key.rs states the keychain-prompt limit as a shortcut:.
    • The CLAUDE.md rule now says that renaming the folder or key orphans the data, and names key.rs.
    • OLD_FOLDER's doc no longer describes a moment in time.
    • A test that said the opposite of half its asserts was renamed.

Suggestions: taken

  • try_exists: a "Hush" folder that can't be looked at counts as there, so the key copy can't replace its key.
  • A lock that fails for a reason other than an older copy holding it says so, instead of "quit it".
  • Failure messages end with "Nothing was moved: open Hush again to try again."
  • A launch at the same time that already did the move counts as done.
  • menuBar.show takes only true/false, and the test checks the shown file.
  • An old login item moves as it was, with the copy of Hush it opens, rather than being re-pointed at whichever build runs first.
  • Comment wording in home.rs, key.rs, settings.rs and notifications.rs.

Declined, with reasons

  • Holding the lock across the rename on Unix. The window is tiny, and a launch inside it still gets AlreadyOpen, because .lock moves with the folder. Windows can't rename a folder with a file open in it, so one path covers both.
  • Logging a failed forget_old once the core's log is up. All that's left behind is a second copy of the same key, under the old name, in the same keychain. Fixing the lost early warnings properly means starting sig-core's log earlier, and this PR doesn't touch sig-core (see the shortcut: comment).
  • Refusing to create a key when the folder already has a database. That is key_in's existing behavior, unchanged here; the guard would change Home's key function. It's a follow-up if wanted.
  • The Mac app creating its folder in the moment between the check and the rename. Its new key would be overwritten. That needs the Swift app's very first launch in the same instant. The rename then fails, nothing moves, and the case is tested.
  • Counting "Hush" as taken only when it holds a core's data. That's a product decision: the issue's rule is "when no Hush folder exists". It goes to the owner.

For the owner

On this Mac, every desktop build now opens the real ~/Library/Application Support/Hush with its key: worktree builds and agents' make desktop-run included. A worktree whose core has newer migrations upgrades the live database. A data-folder override for development builds would keep them apart. Whether to add one is your call.

… there

For development and testing only: with the variable set, the data is in that
folder and its key in dev-key (0600) beside it, made on first use; the
keychain, the real Hush folder, the Hush Desktop move, the login item and the
Mac app's settings are left alone. CLAUDE.md says agents and scripts that
launch the app set it; make perf keeps measuring the owner's linked data.
@pitis

pitis commented Nov 29, 2026

Copy link
Copy Markdown
Owner Author

HUSH_DATA_DIR is in (38bf7e2), as decided. When it is set and not empty, the app uses that folder, with its key in dev-key (0600) there. It never asks the keychain, and it skips the "Hush Desktop" move, the login item replacement and the Mac app's settings import. The README and CLAUDE.md say it's for development and testing only; CLAUDE.md also says agents and scripts that launch the app must set it.

make perf keeps measuring the real linked data: a throwaway folder isn't linked, so its launch never reaches the chat list. A caller's own HUSH_DATA_DIR is used as set. "Hush" still wins over "Hush Desktop", as built.

New tests cover the choice with the variable set, empty or unset, using a fake keychain and folder step that fail the test if called, plus the key file. The ones for new behavior failed against stubs first. Merged with main (already current); the gate passes on the merged head (fmt, both clippy runs, tests: desktop 363, core 541).

@pitis
pitis merged commit 712c24c into main Nov 29, 2026
@pitis
pitis deleted the feat/take-over-mac-data branch November 29, 2026 15:46
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.

On macOS the GPUI app takes over the Mac app's data, so nothing needs relinking

1 participant