diff --git a/brightray/browser/mac/cocoa_notification.h b/brightray/browser/mac/cocoa_notification.h index dcc430099fe5..9e7b55fabfdd 100644 --- a/brightray/browser/mac/cocoa_notification.h +++ b/brightray/browser/mac/cocoa_notification.h @@ -32,6 +32,8 @@ class CocoaNotification : public Notification { NSUserNotification* notification() const { return notification_; } private: + void LogAction(const char* action); + base::scoped_nsobject notification_; int action_index_; diff --git a/brightray/browser/mac/cocoa_notification.mm b/brightray/browser/mac/cocoa_notification.mm index 5e51974b3e46..0ca6512e04e2 100644 --- a/brightray/browser/mac/cocoa_notification.mm +++ b/brightray/browser/mac/cocoa_notification.mm @@ -28,12 +28,19 @@ CocoaNotification::~CocoaNotification() { void CocoaNotification::Show(const NotificationOptions& options) { notification_.reset([[NSUserNotification alloc] init]); + + NSString* identifier = [NSString stringWithFormat:@"%s%d", "ElectronNotification", g_identifier_]; + [notification_ setTitle:base::SysUTF16ToNSString(options.title)]; [notification_ setSubtitle:base::SysUTF16ToNSString(options.subtitle)]; [notification_ setInformativeText:base::SysUTF16ToNSString(options.msg)]; - [notification_ setIdentifier:[NSString stringWithFormat:@"%s%d", "ElectronNotification", g_identifier_]]; + [notification_ setIdentifier:identifier]; g_identifier_++; + if (getenv("ELECTRON_DEBUG_NOTIFICATIONS")) { + NSLog(@"%s (%@)", "Cocoa notification created", identifier); + } + if ([notification_ respondsToSelector:@selector(setContentImage:)] && !options.icon.drawsNothing()) { NSImage* image = skia::SkBitmapToNSImageWithColorSpace( @@ -74,22 +81,38 @@ void CocoaNotification::Dismiss() { if (notification_) [NSUserNotificationCenter.defaultUserNotificationCenter removeDeliveredNotification:notification_]; + NotificationDismissed(); + + this->LogAction("dismissed"); } void CocoaNotification::NotificationDisplayed() { if (delegate()) delegate()->NotificationDisplayed(); + + this->LogAction("displayed"); } void CocoaNotification::NotificationReplied(const std::string& reply) { if (delegate()) delegate()->NotificationReplied(reply); + + this->LogAction("replied to"); } void CocoaNotification::NotificationButtonClicked() { if (delegate()) delegate()->NotificationAction(action_index_); + + this->LogAction("clicked"); +} + +void CocoaNotification::LogAction(const char* action) { + if (getenv("ELECTRON_DEBUG_NOTIFICATIONS")) { + NSString* identifier = [notification_ valueForKey:@"identifier"]; + NSLog(@"%s %s (%@)", "Cocoa notification", action, identifier); + } } } // namespace brightray