Unify notification id; Use user info for notification id

This commit is contained in:
Max Risukhin 2018-10-15 23:30:16 +03:00 committed by Max Risuhin
parent f60befda61
commit 36d0038053
No known key found for this signature in database
GPG Key ID: BF733F5ACA0B4448
3 changed files with 17 additions and 9 deletions

View File

@ -22,17 +22,25 @@
#include "libsnore/plugins/plugins.h"
#include "libsnore/snore.h"
#include <QDateTime>
#include <QSharedData>
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()),

View File

@ -94,7 +94,6 @@ private:
SnorePlugin *m_source = nullptr;
static uint notificationCount;
static uint m_idCount;
friend class Notification;
friend class SnoreCorePrivate;

View File

@ -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);