diff options
author | Tobias Markmann <tm@ayena.de> | 2016-02-12 16:09:32 (GMT) |
---|---|---|
committer | Tobias Markmann <tm@ayena.de> | 2016-02-12 16:09:32 (GMT) |
commit | c3ca881c2f08930c0fd280bc2f41af89986770a8 (patch) | |
tree | cf3f68d979a54264e5d6f4c3cfe037d1bd02e79d | |
parent | d1d2c19154bcd94e1895624bc3a1ac048fe1b569 (diff) | |
download | swift-c3ca881c2f08930c0fd280bc2f41af89986770a8.zip swift-c3ca881c2f08930c0fd280bc2f41af89986770a8.tar.bz2 |
Fix bug in OS X Notification Center backend on empty callback
Checked Growl and Snarl backends which both already do
the check for empty callbacks.
Test-Information:
Tested clicking on an disconnect notification of Swift on
OS X 10.11.3 which previously caused a crash. Now it does not
crash anymore in this case.
Change-Id: I7045ab22a0322cc7a50761640a9b89ba2302acef
-rw-r--r-- | SwifTools/Notifier/NotificationCenterNotifier.mm | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/SwifTools/Notifier/NotificationCenterNotifier.mm b/SwifTools/Notifier/NotificationCenterNotifier.mm index 74d814e..10319c8 100644 --- a/SwifTools/Notifier/NotificationCenterNotifier.mm +++ b/SwifTools/Notifier/NotificationCenterNotifier.mm @@ -1,32 +1,32 @@ /* - * Copyright (c) 2015 Isode Limited. + * Copyright (c) 2015-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include <SwifTools/Notifier/NotificationCenterNotifier.h> #include <map> #include <string> #include <boost/smart_ptr/make_shared.hpp> #include <Swiften/Base/Log.h> #import <Cocoa/Cocoa.h> #include <SwifTools/Notifier/NotificationCenterNotifierDelegate.h> #include <SwifTools/Cocoa/CocoaUtil.h> namespace { struct Context { Context(const boost::function<void()>& callback) : callback(new boost::function<void()>(callback)) { } ~Context() { delete callback; } boost::function<void()>* callback; }; } @@ -57,38 +57,40 @@ void NotificationCenterNotifier::showMessage(Type type, const std::string& subje if (std::find(defaultTypes.begin(), defaultTypes.end(), type) == defaultTypes.end()) { return; } NSImage* image = [[NSImage alloc] initWithContentsOfFile: STD2NSSTRING(picture.string())]; NSUserNotification* notification = [[NSUserNotification alloc] init]; [notification setTitle:STD2NSSTRING(typeToString(type))]; [notification setSubtitle:STD2NSSTRING(subject)]; [notification setInformativeText:STD2NSSTRING(description)]; [notification setContentImage: image]; [image release]; // The OS X Notification Center API does not allow to attach custom data, like a pointer to a callback function, // to the NSUserNotification object. Therefore we maintain a mapping from a NSUserNotification instance's identification // to their respective callbacks. [notification setIdentifier:[[NSUUID UUID] UUIDString]]; /// \todo Currently the elements are only removed on application exit. Ideally the notifications not required anymore /// are removed from the map; e.g. when visiting a chat view, all notifications from that view can be removed from /// the map and the NSUserNotificationCenter. p->callbacksForNotifications[NS2STDSTRING(notification.identifier)] = boost::make_shared<Context>(callback); [[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:notification]; [notification release]; } void NotificationCenterNotifier::purgeCallbacks() { p->callbacksForNotifications.clear(); } void NotificationCenterNotifier::handleUserNotificationActivated(const std::string& identifier) { if (p->callbacksForNotifications.find(identifier) != p->callbacksForNotifications.end()) { - (*p->callbacksForNotifications[identifier]->callback)(); + if (!(*p->callbacksForNotifications[identifier]->callback).empty()) { + (*p->callbacksForNotifications[identifier]->callback)(); + } } else { SWIFT_LOG(warning) << "Missing callback entry for activated notification. The activate notification may come from another instance." << std::endl; } } } |