mac-usernotifications
A wrapper around macOS UNUserNotificationCenter in Rust.
- actionable notifications (buttons, reply fields)
- async and blocking
- updating of notifications
- MacOS only (iOS only features are intentionally omitted)
Usage
[!Note] Notifications require a bundled app. Use
./run_bundled_example.sh $EXAMPLE_NAMEto bundle and run the examples.
Simple async notifications and closing handling
default
.title
.subtitle
.message
.default_sound
.send.await?;
info!;
let response = default
.title
.subtitle
.message
.send.await?
.response.await?;
if response.is_default_action
if response.is_dismiss_action
Action buttons (blocking)
let notification = new
.title
.message
.action
.action
.action
.timeout;
let response = notification
.send_blocking
.and_then;
match response
Reply actions (async)
Reply actions open an inline text field; the typed text arrives in response.reply_text.
new
.title
.message
.action
.action
.action
.timeout
.send
.await
Requirements
- A valid
.appbundle with aCFBundleIdentifier(UNUserNotificationCenterrequires this) (usecargo-bundleto set it up) - Notification permission granted by the user
Threading
Callbacks always arrive on the main thread's run loop. GUI apps (AppKit, SwiftUI, Tauri) handle this automatically. CLI tools and Tokio apps need extra care; see the crate docs for details.
[!Warning]
#[tokio::main]occupies the main thread, so callbacks never fire. Use anew_multi_threadruntime on background threads and keep the main thread free forNSRunLoop. Seeexamples/simple_tokio.rs.
Related Work
-
mac-notification-sys
a thin Objective-C wrapper aroundNSUserNotificationCenter; used as the macOS backend fornotify-rust. Supports basic fire-and-forget delivery with an optional sound; response handling is limited to aNotificationResponseenum (clicked, button clicked, replied, etc.) with no async support or per-notification typed responses. -
user-notify
most similar to this crate, wrapsUNUserNotificationCenterand provides async response handling using Tokio. -
mac-usernotificationsTHIS CRATE
wrapsUNUserNotificationCenterwith support for fire-and-forget and actionable notifications (buttons, reply fields), both async and blocking, with per-notification typed responses and optional timeouts. Does not require Tokio; async support is runtime-agnostic and works on the main-thread run loop viablock_on_main. This aims to be similar in API tomac-notification-systo fit well intonotify-rust.
License
mac-usernotifications is licensed under either of Apache License, Version 2.0 or MIT license at your option.