Mercurial > dwindows
comparison mac/dw.m @ 2106:50196f67a129
Mac: Fixed the clicked callback for notifications on Mojave 10.14+ UNUserNotificationCenter.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Tue, 16 Jun 2020 04:45:30 +0000 |
parents | 2417bc294e30 |
children | b71f46cd58b9 |
comparison
equal
deleted
inserted
replaced
2105:10c22853b479 | 2106:50196f67a129 |
---|---|
3283 } | 3283 } |
3284 -(void)performClick:(id)sender { [textfield performClick:sender]; } | 3284 -(void)performClick:(id)sender { [textfield performClick:sender]; } |
3285 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; } | 3285 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; } |
3286 @end | 3286 @end |
3287 | 3287 |
3288 #ifdef BUILDING_FOR_MOJAVE | |
3289 API_AVAILABLE(macos(10.14)) | |
3290 @interface DWUserNotificationCenterDelegate : NSObject <UNUserNotificationCenterDelegate> | |
3291 @end | |
3292 | |
3293 @implementation DWUserNotificationCenterDelegate | |
3294 //Called when a notification is delivered to a foreground app. | |
3295 -(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler API_AVAILABLE(macos(10.14)) | |
3296 { | |
3297 completionHandler(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge); | |
3298 } | |
3299 //Called to let your app know which action was selected by the user for a given notification. | |
3300 -(void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)(void))completionHandler API_AVAILABLE(macos(10.14)) | |
3301 { | |
3302 NSScanner *objScanner = [NSScanner scannerWithString:response.notification.request.identifier]; | |
3303 unsigned long long handle; | |
3304 HWND notification; | |
3305 | |
3306 // Skip the dw-notification- prefix | |
3307 [objScanner scanString:@"dw-notification-" intoString:nil]; | |
3308 [objScanner scanUnsignedLongLong:&handle]; | |
3309 notification = DW_UINT_TO_POINTER(handle); | |
3310 | |
3311 if ([response.actionIdentifier isEqualToString:UNNotificationDismissActionIdentifier]) | |
3312 { | |
3313 // The user dismissed the notification without taking action. | |
3314 dw_signal_disconnect_by_window(notification); | |
3315 } | |
3316 else if ([response.actionIdentifier isEqualToString:UNNotificationDefaultActionIdentifier]) | |
3317 { | |
3318 // The user launched the app. | |
3319 _event_handler(notification, nil, 8); | |
3320 dw_signal_disconnect_by_window(notification); | |
3321 } | |
3322 completionHandler(); | |
3323 } | |
3324 @end | |
3325 #endif | |
3326 | |
3288 /* Subclass for a MDI type | 3327 /* Subclass for a MDI type |
3289 * This is just a box for display purposes... but it is a | 3328 * This is just a box for display purposes... but it is a |
3290 * unique class so it can be identified when creating windows. | 3329 * unique class so it can be identified when creating windows. |
3291 */ | 3330 */ |
3292 @interface DWMDI : DWBox {} | 3331 @interface DWMDI : DWBox {} |
10827 // Schedule the notification. | 10866 // Schedule the notification. |
10828 if (@available(macOS 10.14, *)) | 10867 if (@available(macOS 10.14, *)) |
10829 { | 10868 { |
10830 if([[NSBundle mainBundle] bundleIdentifier] != nil) | 10869 if([[NSBundle mainBundle] bundleIdentifier] != nil) |
10831 { | 10870 { |
10832 UNMutableNotificationContent *content = (UNMutableNotificationContent *)notification; | 10871 UNMutableNotificationContent* content = (UNMutableNotificationContent *)notification; |
10833 NSString *notid = [NSString stringWithFormat:@"dw-notification-%llu", (unsigned long long)notification]; | 10872 NSString *notid = [NSString stringWithFormat:@"dw-notification-%llu", (unsigned long long)notification]; |
10834 UNNotificationRequest* request = [UNNotificationRequest requestWithIdentifier:notid | 10873 UNNotificationRequest* request = [UNNotificationRequest requestWithIdentifier:notid content:content trigger:nil]; |
10835 content:content trigger:nil]; | |
10836 | 10874 |
10837 UNUserNotificationCenter* center = [UNUserNotificationCenter currentNotificationCenter]; | 10875 UNUserNotificationCenter* center = [UNUserNotificationCenter currentNotificationCenter]; |
10838 [center addNotificationRequest:request withCompletionHandler:^(NSError * _Nullable error) { | 10876 [center addNotificationRequest:request withCompletionHandler:nil]; |
10839 _event_handler(notification, nil, 8); | |
10840 }]; | |
10841 } | 10877 } |
10842 } | 10878 } |
10843 else | 10879 else |
10844 #endif | 10880 #endif |
10845 { | 10881 { |
12138 UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; | 12174 UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; |
12139 if(center) | 12175 if(center) |
12140 { | 12176 { |
12141 [center requestAuthorizationWithOptions:UNAuthorizationOptionAlert|UNAuthorizationOptionSound | 12177 [center requestAuthorizationWithOptions:UNAuthorizationOptionAlert|UNAuthorizationOptionSound |
12142 completionHandler:^(BOOL granted, NSError * _Nullable error) { | 12178 completionHandler:^(BOOL granted, NSError * _Nullable error) { |
12143 if (!granted) { | 12179 if (granted) |
12180 { | |
12181 center.delegate = [[DWUserNotificationCenterDelegate alloc] init]; | |
12182 } | |
12183 else | |
12184 { | |
12144 NSLog(@"WARNING: Unable to get notification permission. %@", error.localizedDescription); | 12185 NSLog(@"WARNING: Unable to get notification permission. %@", error.localizedDescription); |
12145 } | 12186 } |
12146 }]; | 12187 }]; |
12147 } | 12188 } |
12148 } | 12189 } |