fix(notifications): stop leaking a thread per macOS system toast (#6597)

With an action handler registered, tauri-plugin-notification shows every macOS toast on a thread of its own that waits for a click. Toasts that are never clicked keep their thread and NSUserNotificationCenter work alive, so the app slowly gets laggy.

macOS now skips the action handler, so toasts are delivered without tracking; clicking one activates the app instead of focusing the exact window that raised it. Windows and Linux keep per-window focus.

Co-authored-by: PawelSzymanski89 <[email protected]>
Цей коміт міститься в:
Paweł SzymańskiтаPawelSzymanski89 authored and GitHub committed 2026-11-28 06:57:19 +08:00
1 джерело cc5d9d95e4
коміт c658b3eb88
1 file changed
+8 -1
+8 -1
Переглянути файл
@@ -3,7 +3,8 @@
//! Driven by `show_system_notification` from the notification store. Honour
//! global `[notifications].systemNotifications`; suppressed while any window is
//! active. Click focuses the window that raised the toast — balloon actions stay
//! in the IDE.
//! in the IDE. On macOS a click only activates the app: tracking clicks there costs
//! a waiting thread per toast.
use parking_lot::Mutex;
use std::collections::HashMap;
@@ -55,6 +56,12 @@ pub fn init(app: &AppHandle) {
if STATE.ready.swap(true, Ordering::AcqRel) {
return;
}
// macOS: with an action handler the plugin parks a thread per toast until it is clicked,
// so ignored toasts pile up threads and NSUserNotificationCenter CPU. A click on a toast
// already brings the app forward there, so leave the handler out.
if cfg!(target_os = "macos") {
return;
}
let handle = app.clone();
if let Err(e) = app.notification().on_action(move |performed| {
if performed.action_id() != "tap" {