Bring mac code into conformance with -Wunguarded-availability

This commit is contained in:
Jeremy Apthorp 2018-04-17 16:45:26 -07:00
parent 27cee90e5e
commit f3c00e96aa
12 changed files with 234 additions and 207 deletions

View file

@ -29,7 +29,8 @@ class CocoaNotification : public Notification {
void NotificationDisplayed();
void NotificationReplied(const std::string& reply);
void NotificationActivated();
void NotificationActivated(NSUserNotificationAction* action);
void NotificationActivated(NSUserNotificationAction* action)
API_AVAILABLE(macosx(10.10));
NSUserNotification* notification() const { return notification_; }

View file

@ -69,18 +69,22 @@ void CocoaNotification::Show(const NotificationOptions& options) {
} else {
// All of the rest are appended to the list of additional actions
NSString* actionIdentifier = [NSString stringWithFormat:@"%@Action%d", identifier, i];
NSUserNotificationAction* notificationAction =
[NSUserNotificationAction actionWithIdentifier:actionIdentifier
title:base::SysUTF16ToNSString(action.text)];
[additionalActions addObject:notificationAction];
additional_action_indices_.insert(std::make_pair(base::SysNSStringToUTF8(actionIdentifier), i));
if (@available(macOS 10.10, *)) {
NSUserNotificationAction* notificationAction =
[NSUserNotificationAction actionWithIdentifier:actionIdentifier
title:base::SysUTF16ToNSString(action.text)];
[additionalActions addObject:notificationAction];
additional_action_indices_.insert(std::make_pair(base::SysNSStringToUTF8(actionIdentifier), i));
}
}
}
i++;
}
if ([additionalActions count] > 0 &&
[notification_ respondsToSelector:@selector(setAdditionalActions:)]) {
[notification_ setAdditionalActions:additionalActions]; // Requires macOS 10.10
if (@available(macOS 10.10, *)) {
[notification_ setAdditionalActions:additionalActions];
}
}
if (options.has_reply) {

View file

@ -41,8 +41,12 @@
notification->NotificationActivated();
} else if (notif.activationType == NSUserNotificationActivationTypeReplied) {
notification->NotificationReplied([notif.response.string UTF8String]);
} else if (notif.activationType == NSUserNotificationActivationTypeAdditionalActionClicked) {
notification->NotificationActivated([notif additionalActivationAction]);
} else {
if (@available(macOS 10.10, *)) {
if (notif.activationType == NSUserNotificationActivationTypeAdditionalActionClicked) {
notification->NotificationActivated([notif additionalActivationAction]);
}
}
}
}
}