Skip to content

feat: native macOS notifications that update in place, withdraw, and open the right page - #44

Merged
fylorn merged 1 commit into
devfrom
feat/native-notices
Sep 18, 2026
Merged

fylorn merged 1 commit into
devfrom
feat/native-notices

Conversation

@fylorn

@fylorn fylorn commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

Summary

The notification bus (#41, #42) needs three things from the system that tauri-plugin-notification cannot do on the desktop:

  • update in place: the same thing is said once, and after that only the count moves
  • withdraw: a recovery takes back what was said
  • click-through: a click lands on the page that can fix the problem

src-tauri/src/notices/macos/ now talks to UNUserNotificationCenter directly.

How it behaves

Authorisation Asked for just before the first notice that should interrupt, not at launch, so the prompt comes with a reason. If refused, notices stay in the app and the prompt is not repeated.
Posting The identifier is the notice's dedupe key. Posting the same key again replaces the notification. Count updates use the passive interruption level, so they replace quietly.
Withdrawal Removes the delivered notification and any pending request with that key.
App in front Only the Notification Centre list, no banner. The toolbar's list already says it.
Click Brings the window back, creating it if the menu-bar app had none, and lands on the notice's page. A window created for the click fetches the page when it mounts; an open window gets it as an event.
tauri dev Runs outside an app bundle, where asking for the notification centre throws. The plugin remains the fallback there.

Verified on a real machine

The shipping app shares its bundle id and ~/.thinkwatch with the copy already running, and running two at once interferes. So the verification did not use it:

  • un.rs holds only the Objective-C calls and depends on neither Tauri nor the bus.
  • A small separate app included that file unchanged under another bundle id, was installed into ~/Applications, and was run. The user clicked Allow and then clicked the notification.

The test and an earlier Swift spike established:

  • An app signed without a team identifier does get authorisation. It only needs to be installed and registered in a normal location. The same bundle launched from a temporary directory is refused outright, without a prompt.
  • Notifications show while the app has no window.
  • Posting the same identifier replaces the notification.
  • Removal withdraws it.
  • Clicks arrive through the Rust-defined delegate. Nothing crashed during the run.

Test plan

  • cargo fmt --check, cargo clippy --all-targets -- -D warnings, cargo test (94)
  • pnpm typecheck, pnpm build, pnpm test
  • Real-machine run of un.rs as above
  • After the next release: the shipping app asks for permission once, on the first notice that interrupts

🤖 Generated with Claude Code

…open the right page

The plugin used until now can only fire and forget on the desktop: no
update by id, no withdrawal, no click callback. The bus needs all three —
the same thing is said once and then only its count moves, a recovery
withdraws what was said, and a click lands on the page that can fix it.

src-tauri/src/notices/macos/ now talks to UNUserNotificationCenter:

- un.rs holds the Objective-C calls and nothing else: authorisation, post
  or replace by identifier, a passive interruption level for count updates
  so they replace quietly, withdrawal, and a delegate that shows nothing
  but the list while the app is in front and reports clicks. It depends on
  neither Tauri nor the bus, so it was verified on a real machine by a
  small separate app that includes the file as-is under another bundle id
  — the shipping app shares its bundle id and data directory with the copy
  the user runs, and two of them at once interfere.
- Authorisation is asked for when the first interrupting notice is about
  to be shown, not at launch, so the prompt arrives with a reason.
- A click brings the window back (recreating it if the menu-bar app had
  none) and lands on the notice's page; a window created for the click
  collects the page when it mounts.

What the machine test established on 2026-09-18: an app signed without a
team identifier does get authorisation, notifications show with no window
open, the same identifier replaces, removal withdraws and clicks arrive —
but only for an app installed and registered in a normal location; one
launched from a temporary directory is refused outright, without a prompt.

tauri dev runs outside an app bundle, where asking for the notification
centre throws, so the plugin remains the fallback there.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@fylorn
fylorn merged commit 4e3212d into dev Sep 18, 2026
2 checks passed
@fylorn
fylorn deleted the feat/native-notices branch September 18, 2026 13:14
@fylorn fylorn mentioned this pull request Sep 18, 2026
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.

1 participant