Skip to content

Desktop notifications can be answered with Reply, play a sound, and group by chat - #250

Merged
pitis merged 5 commits into
mainfrom
feat/desktop-notification-reply
Nov 29, 2026
Merged

pitis merged 5 commits into
mainfrom
feat/desktop-notification-reply

Conversation

@pitis

@pitis pitis commented Nov 28, 2026 •

Copy link
Copy Markdown
Owner

What changed

Message notifications in the desktop app now have Reply, play a sound and group by chat, as far as each system allows. The Mac app does all three (Notifications.swift, AppStore.replyFromNotification).

Reply Sound Grouping by chat
Windows (toasts) A text box with Send, beside Mark as Read The system's default sound (GPUI's toasts were silent) Toasts sit under a header with the chat's name in the notification center (only when the setting shows names). Group is set to the chat too.
Linux (freedesktop, D-Bus) Shown where the server reports the inline-reply capability (KDE Plasma). On GNOME, which doesn't support it, a click still opens the chat ready to type. Asked for with the sound-name hint message-new-instant, plus the category im.received. It plays where the server plays sounds. The spec has no standard for it, so there is no grouping. The shade lists notifications under the app.
macOS No change: still GPUI's notifications. See below.
  • What a reply does. It sends the trimmed text through the same send_text call the composer uses for plain text: no draft, no quote, no preview, as on the Mac. If the chat is unread, it is then marked read. A blank reply does nothing.
  • When a reply fails. This includes, on Windows, typed text that couldn't be read. The error banner says "Your reply couldn't be sent: …". A "Reply not sent" notification appears, one per chat (<chat>|reply-failed), saying "Open the chat to send it again." or "Its chat is no longer in Hush.". Opening the chat takes it back. These are the Mac's words and rules.
  • Two paths no longer compete on Windows and Linux. The app now shows, takes back and listens to its own notifications there (notifications/toast.rs, notifications/freedesktop.rs), and never calls GPUI's. GPUI's SystemNotification stays in use only on macOS and in tests, where the test platform records it.
  • Linux can now take notifications back. Before, it never did. Now a chat opened, read or deleted, or a message deleted or expired, closes its notifications (CloseNotification). A newer notification with the same tag replaces the older one (replaces_id). This covers only notifications shown in this run, because the server's ids from earlier runs aren't known.
  • Windows takes notifications back from the screen and from the notification center. It removes them by tag and group, which also covers notifications from before the app last started. The tag is hashed with FNV-1a, so it is the same in every build.
  • No notification outlives Hush on Windows or Linux (the owner's call). After Hush quits, nothing would hear a click, a Mark as Read or a reply typed in: Windows has no COM activator, and on Linux nobody is listening on D-Bus. The orderly stop, run by the menu's Quit (⌘Q/Ctrl+Q), the tray's Quit and the Dock/logout path, clears them, unread ones too:
    • Windows: this run's toasts are hidden, then all of the app's are removed from the notification center (History.ClearWithId).
    • Linux: the D-Bus thread closes every notification it showed this run (CloseNotification). It isn't waited for; it runs while the core stops.
    • Only the Hush that had the data clears. A second launch that was refused the data leaves the running one's notifications alone.
    • A shortcut: notes the limits: a crash leaves them (on Windows, until the next quit); Linux keeps earlier runs' notifications, whose ids aren't known, and those of a logout, which ends Hush without asking it.
  • Other people's words stay words. On Linux the body is escaped when the server reads it as markup (body-markup). Characters XML refuses are dropped, on Linux and in Windows toasts.
  • Code layout. The parts that don't depend on the OS are pure and tested in notifications.rs: what a click asks for, the reply-failed tag and the chat's name. The per-OS layer is thin. Pure builders for what each system is sent are also tested: the toast XML and the freedesktop actions and signals.
  • Dependency. windows 0.62 is added for Windows only, with features Data_Xml_Dom, Foundation_Collections and UI_Notifications. It is already in the tree through GPUI, so Cargo.lock gains one dependency line and no new crate. Linux uses the zbus 5 that is already a dependency.

macOS: left as is

GPUI's macOS notifications use UNUserNotificationCenter. GPUI turns them off entirely unless the app runs from a bundle, and the desktop app runs unbundled. When bundled, GPUI's own delegate receives every response and drops the typed text, and GPUI sets no sound and no thread. Reply and sound would need an app bundle (packaging is a separate issue that hasn't started), plus our own delegate in place of GPUI's. A shortcut: comment on the macOS show says so. The Mac has the Swift app, which already does all three.

How it was tested

Gate, run 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

The Swift leg (xcodebuild) was skipped because nothing in app/ changed.

New tests. Each one failed when the code was mutated back to the old behavior: a reply treated as a click, a silent toast, no inline-reply.

  • Pure tests: what a click, Mark as Read and a reply ask for (trimmed; blank → nothing); the chat's name only when the setting shows names; the reply-failed tag; the toast XML (reply box, buttons, header, escaping, no audio); the freedesktop actions by capability and content; the server's signals read as a click, Mark as Read or a reply.
  • More pure tests: escaping, the toast tag's hash (pinned to FNV-1a's published value), and a "Reply not sent" with no chat that finds its chat by tag.
  • Window tests (headless GPUI):
    • A reply on an unlinked core shows the banner and a "Reply not sent" notification with no buttons. The window isn't brought up. Opening the chat takes back both notifications.
    • A reply to a chat no longer listed, or sent before Hush is ready, says so.
    • A "Reply not sent" after a reaction outlasts the chat being read, as the reaction does.
    • A sent reply asks the core to mark its chat read, if unread or marked unread.

Windows and Linux code was type-checked but never run. Only the pure parts run here. toast.rs and freedesktop.rs were type-checked and linted with cargo clippy --target x86_64-pc-windows-msvc and --target x86_64-unknown-linux-gnu in a scratch crate that includes the two files, with the lockfile's versions. Both pass with -D warnings. Also type-checked:

  • the cfg(not(any(test, target_os = "macos"))) glue in notifications.rs. This one was compiled with cargo check by temporarily switching its cfg on macOS and stubbing system (not committed).

Never run:

  • an actual toast, its reply box, its Activated and Failed events or its UserInput
  • clearing at quit. On Windows it is one WinRT call, which was type-checked. On Linux, the bookkeeping of the server's ids moved into a Live map whose tests check that quitting closes exactly the ids on show (it failed when take_all didn't drain). The D-Bus call itself was type-checked.
  • an actual D-Bus notification server, its inline-reply or the NotificationReplied signal
  • the sound on either system
  • a successful reply. The test core isn't linked, so sending always fails.

No snapshot: nothing in the window looks different. The error banner is the existing one.

Closes #233

…roup by chat

Windows and Linux now send their own notifications instead of GPUI's, which
are silent and can't take typed text. Windows toasts get a reply box, Mark as
Read, the system sound, and a header per chat. Linux freedesktop
notifications over D-Bus play message-new-instant, offer inline-reply where
the server supports it, and can now be taken back. A reply is sent like
plain composer text, then the chat is marked read. If it fails, "Reply not
sent" appears, as on the Mac. macOS keeps GPUI's notifications until the app
ships as a bundle.
- A "Reply not sent" notification with no chat listed now opens its chat
  once the chat is listed: chat_named checks this run's chat before the tag
  fallback.
- On Linux, the body is escaped when the server reads it as markup, and
  characters XML refuses are dropped there and in Windows toasts.
- A Windows reply whose text couldn't be read now says "Reply not sent".
  Failed reads and toasts Windows rejects are logged.
- Windows hashes tags with FNV-1a, which gives the same hash in every build
  (DefaultHasher doesn't promise that), and hides a toast still on screen
  when taking it back.
- On Linux, failing to read the server's capabilities no longer turns
  notifications off, and a click that won't decode is logged.
- Shown.reaction is now Shown.unread, which says what it decides.
- Comments now match what each platform does.
@pitis

pitis commented Nov 28, 2026

Copy link
Copy Markdown
Owner Author

Review (/pr-review-toolkit:review-pr on git diff origin/main...HEAD)

Five reviewers looked at this diff: code, silent failures, tests, comments and types. None found anything Critical. The fixes are in 3a2cd53.

Important: fixed

  1. A "Reply not sent" notification with no chat listed couldn't open its chat later. It was recorded with an empty chat (""). chat_named took that empty chat, skipped the tag fallback, and the filter then dropped it. Reported by the types, comments, tests and code reviewers. Fix: chat_named now checks that this run's chat is listed before falling back to the tag. Pure test added.
  2. Linux sent the body raw to servers that read it as markup (KDE and GNOME advertise body-markup), so another person's <a href> or <b> would render. Fix: the body is escaped when the server advertises body-markup. Escape test added.
  3. Windows: typed text that didn't read vanished silently. Fix: Asked::Reply(None) now shows "Reply not sent" ("what was typed couldn't be read"). Each failed read is logged (error only).
  4. Windows: there was no ToastNotification::Failed handler, so a toast Windows rejected left no trace. Fix: the handler is added and logs the error code.
  5. The tag hash wasn't stable across Rust releases. DefaultHasher doesn't promise that, so after a toolchain bump message_gone couldn't find an earlier run's toasts. Fix: FNV-1a, pinned by a test to its published value.
  6. No test covered marking the chat read after a sent reply. Fix: that step is now replied(), tested on unread and marked-unread chats.
  7. No test pinned that a "Reply not sent" outlasts a read. Fix: a window test replies to a reaction in a read chat and checks that both notifications stay after a chat-list update.
  8. No test covered the "Hush wasn't ready" path. Fix: it is now in the chat-gone window test.
  9. The module header said the limits were the system's. On macOS they are GPUI's, and Linux only asks for the sound. Fix: reworded.
  10. message_gone claimed parity with AppStore for earlier runs. Earlier runs' reactions, which quote the message, stay. Fix: the comment says so, with a shortcut:.
  11. The cfg(not(any(test, target_os = "macos"))) glue in notifications.rs had never been compiled. Fix: it was type-checked against GPUI by temporarily switching its cfg on macOS and stubbing system. That change is not committed. toast.rs and freedesktop.rs were cross-checked again for both targets.

Minor: fixed

  • Linux: failing to read GetCapabilities no longer ends the notification thread. It warns and goes on without inline reply. A click or reply whose signal won't decode is now logged.
  • Escaping: characters XML refuses (C0 controls, U+FFFE, U+FFFF) are dropped in Windows toasts and in Linux markup. One of them used to lose the whole toast.
  • Windows: taking a toast back also hides it if it is still on screen (Hide, as GPUI does), besides removing it from the history.
  • Naming: Shown.reaction is now Shown.unread, which says what it decides. Before, a "Reply not sent" was recorded as reaction: true.
  • Comments: the docs of reply_failed_tag, REPLY and chat_named, the reply, listen and Toasts.shown comments, the freedesktop comments, the macOS shortcut: (which now notes that the center keeps one delegate) and the two Cargo.toml dependency comments were corrected.

Declined

  • Retrying CreateToastNotifierWithId on each show: a failure there means a broken Windows setup. It is logged once, and retrying would add state for it.
  • A panic hook for the Linux thread: no other thread in the app has one.
  • A Live struct so Linux's id bookkeeping can be tested: it is about 10 lines of map code that can't run here anyway. A struct would add code without making anything run.
  • Renaming Ask to Call: the two names live in different modules and are never in scope together.
  • A "when to upgrade" on start_over's shortcut:: that line predates this PR.
  • Putting "Reply not sent" under its chat's header on Windows: cosmetic. It would need the chat's name and the setting at that point.
  • Waiting for Hush to be ready before "its chat is gone", as the Mac's ready() does: this behaviour predates the PR for clicks. On Windows and Linux a click can only come while the app runs, so it matters only in the moment of a relink.
  • A click-on-"Reply not sent" window test: the pure chat_named test and the existing click tests cover it.

For the owner (not fixed)

  • Windows toasts outlive the app. There is no COM activator, so after Hush quits, a click, Mark as Read or a reply typed into an old toast reaches nothing. A typed reply is lost without a word. Under GPUI the same was already true for clicks and Mark as Read. The options:
    • (a) SetExpiresOnReboot(true) and clear the app's toasts on quit. Small, but unread notifications go when Hush quits.
    • (b) Register a COM activator, so Windows relaunches Hush with the reply. Larger.
  • send_text only queues the message. "Reply not sent" covers local refusals only. A reply that fails later on the network shows as not sent inside the chat, which was already marked read. The Mac app does the same.

Nothing hears a click on a toast after Hush quits: no COM activator
relaunches it. A reply typed into one would be lost. The orderly stop that
the menu's and the tray's Quit and the Dock or logout path run now removes
Hush's toasts, from the screen and the notification center. Only the Hush
that had the data does this, so a launch that was refused it leaves the
running one's toasts alone.
@pitis

pitis commented Nov 29, 2026

Copy link
Copy Markdown
Owner Author

Windows toasts are cleared at quit (owner's call, 2026-11-29)

This is in 65f9e35, on top of a merge of origin/main (#248, #249). The merge had no conflicts.

  • What changed: app::stop, which runs for the menu's and tray's Quit and for the Dock/logout on_app_quit, now calls notifications::quitting(). On Windows that hides the toasts shown in this run and calls ToastNotificationHistory::ClearWithId(APP_ID), so none stays on screen or in the notification center, including earlier runs'. Off Windows it does nothing.
  • Only in the Hush that had the core open. A launch that was refused the data never showed any toasts. If it quits, it must not remove the running Hush's toasts.
  • Limits (shortcut: on quitting): a crash leaves the toasts until the next quit. Linux's notifications stay (on KDE, a reply typed into one after Hush quits reaches nothing). A COM activator would fix Windows for good.
  • Tests: none could be added. It is one WinRT call, and off Windows it is a no-op. Cross-target clippy passes for Windows and Linux, and the whole gate passes on the merged head.

As with Windows' toasts: nothing hears a click or a reply typed into one
after Hush quits. The D-Bus thread now closes every notification it shows
this run when the orderly stop asks, and again only in the Hush that had
the data. The server-id bookkeeping moves into a small Live map that can
be tested.
@pitis

pitis commented Nov 29, 2026

Copy link
Copy Markdown
Owner Author

Linux notifications are closed at quit too (owner's call, 2026-11-29)

This is in 79cd3e3. The branch is up to date with origin/main.

  • What changed: notifications::quitting() now asks the D-Bus thread to close every notification it showed this run (Ask::Clear → CloseNotification for each id held). As on Windows, this happens only in the Hush that had the core open. It isn't waited for; it runs while the core stops.
  • Tests: the server-id bookkeeping (replace, closed by the server, the tag of an id, take back) moved out of the D-Bus loop into a small Live map. Two new tests cover it, including that quitting closes exactly the ids on show and only once. The quitting test failed when take_all didn't drain.
  • Limits (shortcut: on quitting): a crash leaves them. Linux also keeps earlier runs' notifications, whose ids aren't known, and those of a logout, which ends Hush without asking it (see running). Portal notifications, which start the app for a click, would make them all answerable.
  • Checks: the full gate passes on the merged head, and cross-target clippy passes for Windows and Linux.

@pitis
pitis merged commit d57c41f into main Nov 29, 2026
@pitis
pitis deleted the feat/desktop-notification-reply branch November 29, 2026 01:25
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.

Desktop notifications can be answered with Reply, play a sound, and group by chat

1 participant