Skip to content

The desktop app notifies of new messages and reactions and badges its unread count - #207

Merged
pitis merged 3 commits into
mainfrom
feat/desktop-notifications
Nov 14, 2026
Merged

pitis merged 3 commits into
mainfrom
feat/desktop-notifications

Conversation

@pitis

@pitis pitis commented Nov 14, 2026 •

Copy link
Copy Markdown
Owner

What changed

The desktop app (core/desktop) now does what the Mac app's Notifications.swift, AppStore.notify and ChatList.badge do, through GPUI's system notifications. Everything is in a new module, src/app/notifications.rs. The shared files only gain small hooks.

  • What gets a notification: each new message (CoreEvent::NewMessage) and each reaction to one of our messages (NewReaction). None while the window is in front and on screen, none for a muted chat (asked of the core at that moment, as on the Mac), none for a message already deleted.
  • What it says: the same words as the Mac app's default "Name, content, and actions" setting. The title is "Ana" or "Ana in Family". The body is the text with mentions shown as "@name", a placeholder's text, or the file's kind ("📷 caption"), or "Attachment". A reaction reads "Ana reacted 👍 to: …". Tags are built from the core's opaque_ids, as on the Mac (the system keeps them).
  • Clicking it: a click brings the window up and opens the chat with the composer focused. Mark as Read marks the chat read (mark_read, through chats::change). The tag starts with the chat's opaque id (the Mac app keeps it in userInfo), so a notification from an earlier run still finds its chat once the chats are loaded.
  • When they are taken back: when the chat is opened or deleted (its reactions go too), and when the chat is read here or on the phone, if one of its notifications is about a message (reactions don't count as unread, as on the Mac). Also when the message expires (MessageExpired; on macOS this also removes one shown in an earlier run, by its tag), or is deleted for everyone (re-checked on MessageChanged). A click in the chat already open takes back that chat's other notifications too.
  • Unread badge: counted as ChatList.badge does: unread messages in chats that aren't archived or muted, plus one per chat marked unread. It is counted again when a timed mute ends (recountWhenAMuteEnds).
    • macOS: the Dock tile's badge label.
    • Linux: the Unity LauncherEntry D-Bus signal (KDE Plasma, Ubuntu's dock, Dash to Dock). It is sent from one long-lived connection on its own thread, because a launcher drops the count of a sender that leaves the bus.
    • Windows: none (see below).
  • App identity: main.rs sets the app identity (dev.pitis.HushDesktop, "Hush"), which unpackaged Windows apps need before they can show toasts. On Linux the window's app_id is set to the same id, so the launcher can match the count to the window.

Dependencies

No new crates; Cargo.lock only gains edges. GPUI has no badge API, so the badge needs:

  • macOS: objc2, objc2-app-kit (NSApplication, NSDockTile) and objc2-foundation (NSString), all already GPUI's own dependencies.
  • Linux: zbus 5, already pulled in by the keyring's Secret Service store, with the same default features.

How it was tested

  • Unit tests, which fail against stubs:

    • the badge count (archived, muted, a mute just ended, marked unread);
    • when the next timed mute ends;
    • what is taken back (chat opened, message gone together with reactions to it, chat read only if a message notification is showing, a newer notification with the same tag replacing the older);
    • the message text (file, placeholder, mentions, blank);
    • the title and body wording.
  • Window tests on GPUI's test platform, which records notifications:

    • nothing is shown while the window is in front, but one is shown under a locked screen;
    • what is shown has the right title, body and Mark as Read button;
    • a reaction names who reacted and the people mentioned, and outlasts a read;
    • a click brings the window up, opens its chat and takes the notification back, also in the chat already open;
    • a read chat, an expired message (also one from an earlier run), a message deleted for everyone and a deleted chat take theirs back;
    • the badge follows the chat list and counts a chat again when its mute ends;
    • Mark as Read asks a real (unlinked) core and takes the chat's notifications back.
  • Unit tests also cover the tag: opaque ids only, one per reactor, and the chat found from it.

    With the hooks in mod.rs removed, two of the three window tests fail.

  • The Linux show_badge was compiled on macOS against zbus 5.19.0 in a scratch crate, to check the types.

  • Gate:

    • make format;
    • make lint (clippy -D warnings, plain and with hush-desktop/snapshot);
    • cd core && cargo test -q --features hush-desktop/snapshot (193 desktop, 537 core).
  • Swift leg: nothing it builds changed (no sig-core or app/ change).

  • No snapshots: nothing is drawn in the window.

Not verified

  • Real notifications and the Dock badge on screen. GPUI shows notifications on macOS only from an app bundle (cargo run has none, so it skips them; GPUI's own info line about it doesn't reach the core's log). The live window can't be captured here, so neither a real notification nor the Dock badge was seen.
  • Windows and Linux weren't built or run (macOS only here).
    • On Linux the count shows only once a dev.pitis.HushDesktop.desktop launcher is installed. No packaging ships one yet.

Decisions for the owner

  1. Notification content setting. The Mac's "Notification content" preference has four choices: name, content and actions / name only / no name or content / off. The desktop has no settings yet (The desktop app edits your profile and settings, and unlinks or relinks this computer #153), so it always shows name and content, the Mac's default. The picker would come with The desktop app edits your profile and settings, and unlinks or relinks this computer #153.
  2. Reply from a notification. GPUI's notification actions are plain buttons with no text field, on every system. A click opens the chat with the composer focused instead, and Mark as Read is kept. Typing a reply in the notification would need our own notification code per platform.
  3. No sound. GPUI posts notifications silently on macOS and Windows; the Mac app plays the default sound.
  4. Taking notifications back on Linux. GPUI can't close a notification there ("stale notifications simply age out of the shade"). A read, deleted or expired message stays in the shade until it ages out, which matters most for disappearing messages. Fixing it would mean closing notifications through org.freedesktop.Notifications ourselves.
  5. Windows badge. Windows shows a count only for apps installed as a package. Signal Desktop draws the count as the taskbar button's overlay icon (ITaskbarList3::SetOverlayIcon). That isn't done here: it would be untested code for icons drawn at runtime. A shortcut: comment marks the spot.
  6. Notifications from an earlier run. Notification Center (macOS) and Action Center (Windows) can keep notifications from an earlier run, and clicking one opens its chat. They aren't cleared at launch: the Mac app removes stale ones by prefix, and GPUI can't list what's delivered.
    • An expired message's notification is removed by its tag (macOS only).
    • An earlier run's reaction notifications are not removed: their tag needs the reactor and emoji.
    • On Windows, GPUI can only remove toasts from the current run.
  7. Other GPUI differences.
    • macOS doesn't group notifications by chat: GPUI sets no thread identifier.
    • GPUI asks for notification permission at the first notification, not at launch, so the very first one may be lost while the prompt is up.
    • On Linux, a newer notification with the same tag doesn't replace the older one.
    • On Linux, GPUI keeps a thread and a D-Bus connection open for each shown notification until it closes.

Closes #146

… unread count

A notification per message come in and per reaction to ours, through GPUI's
system notifications, worded as the Mac app's; none while the window is in
front or for a muted chat. A click opens the chat, Mark as Read marks it read.
They are taken back when their chat is opened, read or deleted, and when their
message is deleted or disappears. The unread count shows on the Dock (macOS)
and on the launcher (Linux, the Unity LauncherEntry signal).
… review

The tag carries the chat's opaque id, so a click or Mark as Read on a
notification from an earlier run finds its chat; a click in the open chat
takes back its other notifications; an expired message's notification goes
also when shown in an earlier run (macOS). The mute-end wait is re-armed only
when the next end changes. Failures are logged (ids and errors only), the
Linux launcher count stays out of tests, and comments say what the code does.
@pitis

pitis commented Nov 14, 2026

Copy link
Copy Markdown
Owner Author

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

There were no Critical findings. Each finding and what was done about it:

Code

  1. Important. The mute-end timer was re-armed on every chat-list refresh. A dropped GPUI task leaves its system timer queued until the mute ends. Fixed: the end is stored with its wait, and the wait is re-armed only when the next end changes. A wait that fires clears itself and counts again. Long waits are capped and simply wait again.
  2. Important. On macOS, an expired message's notification from an earlier run stayed readable. Fixed: message_gone also removes the message's own tag, which is built the same way every run. This works on macOS. Windows can only remove the current run's toasts, and Linux removes nothing. An earlier run's reaction notifications aren't removed. Both are now in the PR body under decision 6.
  3. Suggestion. The Linux badge would reach a real launcher while tests run. Fixed: it returns early under cfg!(test).
  4. Suggestion. GPUI differences missing from the PR body. Added as decision 7: no grouping by chat on macOS, permission asked at the first notification, same-tag replace not on Linux, and a thread per notification on Linux.
  5. Suggestion. Log style. Fixed: every warning uses error = %e.

Error handling

  1. Important. A failed deletion check gave up silently. Fixed: it is logged (error only), and the notification stays.
  2. Important. A click or Mark as Read on a notification with an unknown chat did nothing, with no trace. Fixed in two ways:
    • It is logged.
    • The tag now starts with the chat's opaque id, as the Mac keeps the chat in userInfo, so a notification from an earlier run finds its chat once the chats are listed.
  3. Important. The PR body said an unbundled macOS build logs that notifications are off. GPUI logs that at info, which the core's filter drops. Fixed: the PR text is corrected. I declined the optional warning of our own: it needs another objc2-foundation feature, and the module doc and the PR already state the limit.
  4. Suggestions. Fixed:
    • The attachment and name lookups now log failures (still non-fatal).
    • responses logs a click that finds no window, as navigate.rs does.

Tests

Added:

  1. A message deleted for everyone is taken back (MessageChanged on a key the core no longer has); a deleted chat takes its notifications back.
  2. show() names who reacted, the group and the people mentioned, and a reaction outlasts the chat being read.
  3. A click brings the window up: the window is deactivated through the platform, and the test checks it becomes active.
  4. A notification is shown when the window is active but not visible (a locked screen).
  5. The badge counts a chat again when its mute ends (the timer task is exercised).
  6. The tag: a pure tag() with unit tests (opaque ids only, one per reactor, the chat found from it).
  7. A click in the chat already open takes back its other notifications. This was a real gap, because select returns early for the open chat. Fixed in used.

Removing the click-time take-back, the window activation or the stored mute wait makes 4 window tests fail.

I declined one test-quality note: the Mark as Read test could in principle pass on the error from mod.rs::mark_read. It now also asserts that the window stays inactive, and an inactive window never marks anything read there.

Comments

All eight were reworded to match the code:

  • the reaction flag;
  • the Linux launcher and .desktop file (none is shipped yet);
  • the module doc's macOS bundle limit;
  • the struct docs;
  • the Linux same-tag replace;
  • chat_seen's callers;
  • the unknown-chat case;
  • the mod.rs note.

After the fixes

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.

The desktop app notifies of new messages and reactions and badges its unread count

1 participant