comparison mac/dw.m @ 2107:b71f46cd58b9

Mac: Implemented notification click callback pre-Mojave 10.14.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Tue, 16 Jun 2020 05:46:22 +0000
parents 50196f67a129
children 251d050d306b
comparison
equal deleted inserted replaced
2106:50196f67a129 2107:b71f46cd58b9
1349 } 1349 }
1350 -(NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender; 1350 -(NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender;
1351 -(void)applicationDidFinishLaunching:(NSNotification *)aNotification; 1351 -(void)applicationDidFinishLaunching:(NSNotification *)aNotification;
1352 #ifdef BUILDING_FOR_MOUNTAIN_LION 1352 #ifdef BUILDING_FOR_MOUNTAIN_LION
1353 -(BOOL)userNotificationCenter:(NSUserNotificationCenter *)center shouldPresentNotification:(NSUserNotification *)notification; 1353 -(BOOL)userNotificationCenter:(NSUserNotificationCenter *)center shouldPresentNotification:(NSUserNotification *)notification;
1354 -(void)userNotificationCenter:(NSUserNotificationCenter *)center didActivateNotification:(NSUserNotification *)notification;
1354 #endif 1355 #endif
1355 @end 1356 @end
1356 1357
1357 /* Apparently the WKWebKit API is only enabled on intel 64bit... 1358 /* Apparently the WKWebKit API is only enabled on intel 64bit...
1358 * Causing build failures on 32bit builds, so this should allow 1359 * Causing build failures on 32bit builds, so this should allow
1454 } 1455 }
1455 #ifdef BUILDING_FOR_MOUNTAIN_LION 1456 #ifdef BUILDING_FOR_MOUNTAIN_LION
1456 -(BOOL)userNotificationCenter:(NSUserNotificationCenter *)center shouldPresentNotification:(NSUserNotification *)notification 1457 -(BOOL)userNotificationCenter:(NSUserNotificationCenter *)center shouldPresentNotification:(NSUserNotification *)notification
1457 { 1458 {
1458 return YES; 1459 return YES;
1460 }
1461 -(void)userNotificationCenter:(NSUserNotificationCenter *)center didActivateNotification:(NSUserNotification *)usernotification
1462 {
1463 NSScanner *objScanner = [NSScanner scannerWithString:usernotification.identifier];
1464 unsigned long long handle;
1465 HWND notification;
1466
1467 // Skip the dw-notification- prefix
1468 [objScanner scanString:@"dw-notification-" intoString:nil];
1469 [objScanner scanUnsignedLongLong:&handle];
1470 notification = DW_UINT_TO_POINTER(handle);
1471
1472 switch(usernotification.activationType)
1473 {
1474 case NSUserNotificationActivationTypeContentsClicked:
1475 _event_handler(notification, nil, 8);
1476 break;
1477 default:
1478 break;
1479 }
1480 dw_signal_disconnect_by_window(notification);
1459 } 1481 }
1460 #endif 1482 #endif
1461 @end 1483 @end
1462 1484
1463 /* Subclass for a top-level window */ 1485 /* Subclass for a top-level window */
10860 int dw_notification_send(HWND notification) 10882 int dw_notification_send(HWND notification)
10861 { 10883 {
10862 #ifdef BUILDING_FOR_MOUNTAIN_LION 10884 #ifdef BUILDING_FOR_MOUNTAIN_LION
10863 if(notification) 10885 if(notification)
10864 { 10886 {
10887 NSString *notid = [NSString stringWithFormat:@"dw-notification-%llu", (unsigned long long)notification];
10888
10865 #ifdef BUILDING_FOR_MOJAVE 10889 #ifdef BUILDING_FOR_MOJAVE
10866 // Schedule the notification. 10890 // Schedule the notification.
10867 if (@available(macOS 10.14, *)) 10891 if (@available(macOS 10.14, *))
10868 { 10892 {
10869 if([[NSBundle mainBundle] bundleIdentifier] != nil) 10893 if([[NSBundle mainBundle] bundleIdentifier] != nil)
10870 { 10894 {
10871 UNMutableNotificationContent* content = (UNMutableNotificationContent *)notification; 10895 UNMutableNotificationContent* content = (UNMutableNotificationContent *)notification;
10872 NSString *notid = [NSString stringWithFormat:@"dw-notification-%llu", (unsigned long long)notification];
10873 UNNotificationRequest* request = [UNNotificationRequest requestWithIdentifier:notid content:content trigger:nil]; 10896 UNNotificationRequest* request = [UNNotificationRequest requestWithIdentifier:notid content:content trigger:nil];
10874 10897
10875 UNUserNotificationCenter* center = [UNUserNotificationCenter currentNotificationCenter]; 10898 UNUserNotificationCenter* center = [UNUserNotificationCenter currentNotificationCenter];
10876 [center addNotificationRequest:request withCompletionHandler:nil]; 10899 [center addNotificationRequest:request withCompletionHandler:nil];
10877 } 10900 }
10878 } 10901 }
10879 else 10902 else
10880 #endif 10903 #endif
10881 { 10904 {
10882 // Fallback on earlier versions 10905 // Fallback on earlier versions
10883 [[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:notification]; 10906 NSUserNotification *request = (NSUserNotification *)notification;
10907 request.identifier = notid;
10908 [[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:request];
10884 } 10909 }
10885 return DW_ERROR_NONE; 10910 return DW_ERROR_NONE;
10886 } 10911 }
10887 #endif 10912 #endif
10888 return DW_ERROR_UNKNOWN; 10913 return DW_ERROR_UNKNOWN;