From eb8d10ed05f8dd5081ed92ccc9798c9961f38924 Mon Sep 17 00:00:00 2001 From: Maarten Billemont Date: Thu, 14 May 2020 10:32:04 -0400 Subject: [PATCH] Use new UN notification API. --- .../Source/Mac/MPSitesWindowController.m | 32 ++++++++++++++----- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/platform-darwin/Source/Mac/MPSitesWindowController.m b/platform-darwin/Source/Mac/MPSitesWindowController.m index 04b39eb2..b15d1466 100644 --- a/platform-darwin/Source/Mac/MPSitesWindowController.m +++ b/platform-darwin/Source/Mac/MPSitesWindowController.m @@ -18,6 +18,7 @@ #import #import +#import #import "MPSitesWindowController.h" #import "MPMacAppDelegate.h" #import "MPAppDelegate_Store.h" @@ -99,7 +100,16 @@ self.siteTable.superview.superview.layer.mask = self.siteGradient; self.siteTable.controller = self; - prof_finish( @"ui" ); + prof_rewind( @"ui" ); + + if (@available( macOS 10.14, * )) { + [[UNUserNotificationCenter currentNotificationCenter] + requestAuthorizationWithOptions:UNAuthorizationOptionAlert completionHandler:^(BOOL granted, NSError *error) { + if (!granted) + err( @"Couldn't obtain notification authorization: %@", error ); + }]; + } + prof_finish( @"notifications" ); } - (void)dealloc { @@ -550,13 +560,19 @@ [self copyContent:self.shiftPressed? selectedSite.loginName: selectedSite.content]; [NSApp hide:nil]; - NSUserNotification *notification = [NSUserNotification new]; - notification.title = @"Password Copied"; - if (selectedSite.loginName.length) - notification.subtitle = strf( @"%@ at %@", selectedSite.loginName, selectedSite.name ); - else - notification.subtitle = selectedSite.name; - [[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:notification]; + if (@available( macOS 10.14, * )) { + UNMutableNotificationContent *notification = [UNMutableNotificationContent new]; + notification.title = self.shiftPressed? @"Login Copied": @"Password Copied"; + if (selectedSite.loginName.length) + notification.subtitle = strf( @"%@ at %@", selectedSite.loginName, selectedSite.name ); + else + notification.subtitle = selectedSite.name; + [[UNUserNotificationCenter currentNotificationCenter] addNotificationRequest: + [UNNotificationRequest requestWithIdentifier:selectedSite.name content:notification trigger:nil] + withCompletionHandler:^(NSError *error) { + dbg( @"notification: %@, completed w/errror: %@", notification, error ); + }]; + } } - (void)updateUser {