From 4df562dfb2475a9057f0f33a8db75808efad8670 Mon Sep 17 00:00:00 2001 From: outfoxxed Date: Fri, 10 Jul 2026 01:58:38 -0700 Subject: [PATCH] service/notifications: emit NotificationClosed after Notify returns --- changelog/next.md | 1 + src/services/notifications/server.cpp | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/changelog/next.md b/changelog/next.md index 0a146fd..585dfb6 100644 --- a/changelog/next.md +++ b/changelog/next.md @@ -9,3 +9,4 @@ - Fixed potential crashes from usage of `WindowsetProjection.screens` during monitor unplug. - Fixed crashes from accessing freed objects laundered through a `ScriptModel`. - Fixed crashes when a wifi network disappear. +- Fixed unhandled notifications sending `NotificationClosed` out of order. diff --git a/src/services/notifications/server.cpp b/src/services/notifications/server.cpp index d2b55d0..1919012 100644 --- a/src/services/notifications/server.cpp +++ b/src/services/notifications/server.cpp @@ -8,6 +8,8 @@ #include #include #include +#include +#include #include #include #include @@ -192,19 +194,29 @@ uint NotificationServer::Notify( notification->updateProperties(appName, appIcon, summary, body, actions, hints, expireTimeout); + auto id = notification->id(); + if (!old) { emit this->notification(notification); if (!notification->isTracked()) { - emit this->NotificationClosed(notification->id(), notification->closeReason()); + auto closeReason = notification->closeReason(); + + // Emit NotificationClosed after Notify returns + QMetaObject::invokeMethod( + this, + [this, id, closeReason]() { emit this->NotificationClosed(id, closeReason); }, + Qt::QueuedConnection + ); + delete notification; } else { - this->idMap.insert(notification->id(), notification); + this->idMap.insert(id, notification); this->mNotifications.insertObject(notification); } } - return notification->id(); + return id; } } // namespace qs::service::notifications