diff --git a/src/libsnore/notification/notification_p.cpp b/src/libsnore/notification/notification_p.cpp index 7e3fc15..12f1ff6 100644 --- a/src/libsnore/notification/notification_p.cpp +++ b/src/libsnore/notification/notification_p.cpp @@ -22,17 +22,25 @@ #include "libsnore/plugins/plugins.h" #include "libsnore/snore.h" +#include #include using namespace Snore; uint NotificationData::notificationCount = 0; -uint NotificationData::m_idCount = 1; +namespace { +uint m_idCount = 1; +} +uint getNewId() { + const QDateTime& d = QDateTime::currentDateTime(); + QString result = QString(QStringLiteral("%1%2")).arg(d.toString(QStringLiteral("Hmmsszzz"))).arg(m_idCount++); + return result.toUInt(); +} NotificationData::NotificationData(const Snore::Application &application, const Snore::Alert &alert, const QString &title, const QString &text, const Icon &icon, int timeout, Notification::Prioritys priority): - m_id(m_idCount++), + m_id(getNewId()), m_timeout(priority == Notification::Emergency ? 0 : timeout), m_application(application), m_alert(alert), @@ -48,7 +56,7 @@ NotificationData::NotificationData(const Snore::Application &application, const } Snore::NotificationData::NotificationData(const Notification &old, const QString &title, const QString &text, const Icon &icon, int timeout, Notification::Prioritys priority): - m_id(m_idCount++), + m_id(getNewId()), m_timeout(priority == Notification::Emergency ? 0 : timeout), m_application(old.application()), m_alert(old.alert()), diff --git a/src/libsnore/notification/notification_p.h b/src/libsnore/notification/notification_p.h index b7969d3..9579cba 100644 --- a/src/libsnore/notification/notification_p.h +++ b/src/libsnore/notification/notification_p.h @@ -94,7 +94,6 @@ private: SnorePlugin *m_source = nullptr; static uint notificationCount; - static uint m_idCount; friend class Notification; friend class SnoreCorePrivate; diff --git a/src/plugins/backends/osxnotificationcenter/osxnotificationcenter.mm b/src/plugins/backends/osxnotificationcenter/osxnotificationcenter.mm index c17b246..e05d9cf 100644 --- a/src/plugins/backends/osxnotificationcenter/osxnotificationcenter.mm +++ b/src/plugins/backends/osxnotificationcenter/osxnotificationcenter.mm @@ -85,12 +85,13 @@ BOOL installNSBundleHook() dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ int notificationId = [notification.userInfo[@"id"] intValue]; - BOOL notificationAvailable = YES; + bool notificationAvailable = true; while(notificationAvailable) { - notificationAvailable = NO; + notificationAvailable = false; for(NSUserNotification *osxNotification in [[NSUserNotificationCenter defaultUserNotificationCenter] deliveredNotifications]) { - if([osxNotification.identifier isEqualToString:notification.identifier]) { - notificationAvailable = YES; + int fetchedNotificationID = [osxNotification.userInfo[@"id"] intValue]; + if(fetchedNotificationID == notificationId) { + notificationAvailable = true; [NSThread sleepForTimeInterval:0.25f]; break; } @@ -154,7 +155,7 @@ void OSXNotificationCenter::slotNotify(Snore::Notification notification) osxNotification.title = notification.title().toNSString(); osxNotification.userInfo = [NSDictionary dictionaryWithObjectsAndKeys:notificationId, @"id", nil]; osxNotification.informativeText = notification.text().toNSString(); - osxNotification.identifier = notificationId; + // osxNotification.identifier = notificationId; // Add notification to mapper from id to Nofification / NSUserNotification m_IdToNotification.insert(notification.id(), notification);