🔧 Allow notifications debugging (macOS)
This commit is contained in:
parent
5720a8e7d5
commit
ffd85bfaac
2 changed files with 26 additions and 1 deletions
|
@ -32,6 +32,8 @@ class CocoaNotification : public Notification {
|
||||||
NSUserNotification* notification() const { return notification_; }
|
NSUserNotification* notification() const { return notification_; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void LogAction(const char* action);
|
||||||
|
|
||||||
base::scoped_nsobject<NSUserNotification> notification_;
|
base::scoped_nsobject<NSUserNotification> notification_;
|
||||||
int action_index_;
|
int action_index_;
|
||||||
|
|
||||||
|
|
|
@ -28,12 +28,19 @@ CocoaNotification::~CocoaNotification() {
|
||||||
|
|
||||||
void CocoaNotification::Show(const NotificationOptions& options) {
|
void CocoaNotification::Show(const NotificationOptions& options) {
|
||||||
notification_.reset([[NSUserNotification alloc] init]);
|
notification_.reset([[NSUserNotification alloc] init]);
|
||||||
|
|
||||||
|
NSString* identifier = [NSString stringWithFormat:@"%s%d", "ElectronNotification", g_identifier_];
|
||||||
|
|
||||||
[notification_ setTitle:base::SysUTF16ToNSString(options.title)];
|
[notification_ setTitle:base::SysUTF16ToNSString(options.title)];
|
||||||
[notification_ setSubtitle:base::SysUTF16ToNSString(options.subtitle)];
|
[notification_ setSubtitle:base::SysUTF16ToNSString(options.subtitle)];
|
||||||
[notification_ setInformativeText:base::SysUTF16ToNSString(options.msg)];
|
[notification_ setInformativeText:base::SysUTF16ToNSString(options.msg)];
|
||||||
[notification_ setIdentifier:[NSString stringWithFormat:@"%s%d", "ElectronNotification", g_identifier_]];
|
[notification_ setIdentifier:identifier];
|
||||||
g_identifier_++;
|
g_identifier_++;
|
||||||
|
|
||||||
|
if (getenv("ELECTRON_DEBUG_NOTIFICATIONS")) {
|
||||||
|
NSLog(@"%s (%@)", "Cocoa notification created", identifier);
|
||||||
|
}
|
||||||
|
|
||||||
if ([notification_ respondsToSelector:@selector(setContentImage:)] &&
|
if ([notification_ respondsToSelector:@selector(setContentImage:)] &&
|
||||||
!options.icon.drawsNothing()) {
|
!options.icon.drawsNothing()) {
|
||||||
NSImage* image = skia::SkBitmapToNSImageWithColorSpace(
|
NSImage* image = skia::SkBitmapToNSImageWithColorSpace(
|
||||||
|
@ -74,22 +81,38 @@ void CocoaNotification::Dismiss() {
|
||||||
if (notification_)
|
if (notification_)
|
||||||
[NSUserNotificationCenter.defaultUserNotificationCenter
|
[NSUserNotificationCenter.defaultUserNotificationCenter
|
||||||
removeDeliveredNotification:notification_];
|
removeDeliveredNotification:notification_];
|
||||||
|
|
||||||
NotificationDismissed();
|
NotificationDismissed();
|
||||||
|
|
||||||
|
this->LogAction("dismissed");
|
||||||
}
|
}
|
||||||
|
|
||||||
void CocoaNotification::NotificationDisplayed() {
|
void CocoaNotification::NotificationDisplayed() {
|
||||||
if (delegate())
|
if (delegate())
|
||||||
delegate()->NotificationDisplayed();
|
delegate()->NotificationDisplayed();
|
||||||
|
|
||||||
|
this->LogAction("displayed");
|
||||||
}
|
}
|
||||||
|
|
||||||
void CocoaNotification::NotificationReplied(const std::string& reply) {
|
void CocoaNotification::NotificationReplied(const std::string& reply) {
|
||||||
if (delegate())
|
if (delegate())
|
||||||
delegate()->NotificationReplied(reply);
|
delegate()->NotificationReplied(reply);
|
||||||
|
|
||||||
|
this->LogAction("replied to");
|
||||||
}
|
}
|
||||||
|
|
||||||
void CocoaNotification::NotificationButtonClicked() {
|
void CocoaNotification::NotificationButtonClicked() {
|
||||||
if (delegate())
|
if (delegate())
|
||||||
delegate()->NotificationAction(action_index_);
|
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
|
} // namespace brightray
|
||||||
|
|
Loading…
Reference in a new issue