From c658b3eb881bff9bbf97f9948cf87e764536ed09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Szyma=C5=84ski?= Date: Fri, 27 Nov 2026 23:57:19 +0100 Subject: [PATCH] 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 <26041449+PawelSzymanski89@users.noreply.github.com> --- src-tauri/src/system_notifications.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src-tauri/src/system_notifications.rs b/src-tauri/src/system_notifications.rs index cc453658d8..6316b8a9de 100644 --- a/src-tauri/src/system_notifications.rs +++ b/src-tauri/src/system_notifications.rs @@ -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" {