a9ef68f126
* refactor: change defined(MAS_BUILD) to IS_MAS_BUILD() This is missing-definition safe and thus allows us to move the definition of this macro away from "all compilation targets" to "just the compilation targets that depend on this macro". In turn this makes the rebuild time changing from mas <-> darwin only 80 seconds on my machine, instead of the 12-15 minutes it used to take. This will also allow us in the future to build both MAS and darwin on the same CI machine. Costing us ~2 minutes on one machine but saving us anywhere from 30 minutes to an hour of CI time on other parts of the matrix. * build: always define IS_MAS_BUILD even on non-mac builds * build: use extra_configs
92 lines
3.2 KiB
Text
92 lines
3.2 KiB
Text
// Copyright (c) 2015 GitHub, Inc.
|
|
// Use of this source code is governed by the MIT license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#include "shell/browser/notifications/mac/notification_center_delegate.h"
|
|
|
|
#include <string>
|
|
|
|
#include "base/logging.h"
|
|
#include "shell/browser/notifications/mac/cocoa_notification.h"
|
|
#include "shell/browser/notifications/mac/notification_presenter_mac.h"
|
|
|
|
@implementation NotificationCenterDelegate
|
|
|
|
- (instancetype)initWithPresenter:
|
|
(electron::NotificationPresenterMac*)presenter {
|
|
self = [super init];
|
|
if (!self)
|
|
return nil;
|
|
|
|
presenter_ = presenter;
|
|
return self;
|
|
}
|
|
|
|
- (void)userNotificationCenter:(NSUserNotificationCenter*)center
|
|
didDeliverNotification:(NSUserNotification*)notif {
|
|
auto* notification = presenter_->GetNotification(notif);
|
|
if (notification)
|
|
notification->NotificationDisplayed();
|
|
}
|
|
|
|
- (void)userNotificationCenter:(NSUserNotificationCenter*)center
|
|
didActivateNotification:(NSUserNotification*)notif {
|
|
auto* notification = presenter_->GetNotification(notif);
|
|
|
|
if (getenv("ELECTRON_DEBUG_NOTIFICATIONS")) {
|
|
LOG(INFO) << "Notification activated (" << [notif.identifier UTF8String]
|
|
<< ")";
|
|
}
|
|
|
|
if (notification) {
|
|
// Ref:
|
|
// https://developer.apple.com/documentation/foundation/nsusernotificationactivationtype?language=objc
|
|
if (notif.activationType ==
|
|
NSUserNotificationActivationTypeContentsClicked) {
|
|
notification->NotificationClicked();
|
|
} else if (notif.activationType ==
|
|
NSUserNotificationActivationTypeActionButtonClicked) {
|
|
notification->NotificationActivated();
|
|
} else if (notif.activationType ==
|
|
NSUserNotificationActivationTypeReplied) {
|
|
notification->NotificationReplied([notif.response.string UTF8String]);
|
|
} else {
|
|
if (notif.activationType ==
|
|
NSUserNotificationActivationTypeAdditionalActionClicked) {
|
|
notification->NotificationActivated([notif additionalActivationAction]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
- (BOOL)userNotificationCenter:(NSUserNotificationCenter*)center
|
|
shouldPresentNotification:(NSUserNotification*)notification {
|
|
// Display notifications even if the app is active.
|
|
return YES;
|
|
}
|
|
|
|
#if !IS_MAS_BUILD()
|
|
// This undocumented method notifies us if a user closes "Alert" notifications
|
|
// https://chromium.googlesource.com/chromium/src/+/lkgr/chrome/browser/notifications/notification_platform_bridge_mac.mm
|
|
- (void)userNotificationCenter:(NSUserNotificationCenter*)center
|
|
didDismissAlert:(NSUserNotification*)notif {
|
|
auto* notification = presenter_->GetNotification(notif);
|
|
if (notification)
|
|
notification->NotificationDismissed();
|
|
}
|
|
#endif
|
|
|
|
#if !IS_MAS_BUILD()
|
|
// This undocumented method notifies us if a user closes "Banner" notifications
|
|
// https://github.com/mozilla/gecko-dev/blob/master/widget/cocoa/OSXNotificationCenter.mm
|
|
- (void)userNotificationCenter:(NSUserNotificationCenter*)center
|
|
didRemoveDeliveredNotifications:(NSArray*)notifications {
|
|
for (NSUserNotification* notif in notifications) {
|
|
auto* notification = presenter_->GetNotification(notif);
|
|
if (notification)
|
|
notification->NotificationDismissed();
|
|
}
|
|
}
|
|
#endif
|
|
|
|
@end
|