changeset 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 35abef6e33a9
files mac/dw.m
diffstat 1 files changed, 27 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mac/dw.m	Tue Jun 16 04:45:30 2020 +0000
+++ b/mac/dw.m	Tue Jun 16 05:46:22 2020 +0000
@@ -1351,6 +1351,7 @@
 -(void)applicationDidFinishLaunching:(NSNotification *)aNotification;
 #ifdef BUILDING_FOR_MOUNTAIN_LION
 -(BOOL)userNotificationCenter:(NSUserNotificationCenter *)center shouldPresentNotification:(NSUserNotification *)notification;
+-(void)userNotificationCenter:(NSUserNotificationCenter *)center didActivateNotification:(NSUserNotification *)notification;
 #endif
 @end
 
@@ -1457,6 +1458,27 @@
 {
     return YES;
 }
+-(void)userNotificationCenter:(NSUserNotificationCenter *)center didActivateNotification:(NSUserNotification *)usernotification
+{
+    NSScanner *objScanner = [NSScanner scannerWithString:usernotification.identifier];
+    unsigned long long handle;
+    HWND notification;
+    
+    // Skip the dw-notification- prefix
+    [objScanner scanString:@"dw-notification-" intoString:nil];
+    [objScanner scanUnsignedLongLong:&handle];
+    notification = DW_UINT_TO_POINTER(handle);
+    
+    switch(usernotification.activationType)
+    {
+        case NSUserNotificationActivationTypeContentsClicked:
+            _event_handler(notification, nil, 8);
+            break;
+        default:
+            break;
+    }
+    dw_signal_disconnect_by_window(notification);
+}
 #endif
 @end
 
@@ -10862,6 +10884,8 @@
 #ifdef BUILDING_FOR_MOUNTAIN_LION
     if(notification)
     {
+        NSString *notid = [NSString stringWithFormat:@"dw-notification-%llu", (unsigned long long)notification];
+        
 #ifdef BUILDING_FOR_MOJAVE
         // Schedule the notification.
         if (@available(macOS 10.14, *))
@@ -10869,7 +10893,6 @@
             if([[NSBundle mainBundle] bundleIdentifier] != nil)
             {
                 UNMutableNotificationContent* content = (UNMutableNotificationContent *)notification;
-                NSString *notid = [NSString stringWithFormat:@"dw-notification-%llu", (unsigned long long)notification];
                 UNNotificationRequest* request = [UNNotificationRequest requestWithIdentifier:notid content:content trigger:nil];
 
                 UNUserNotificationCenter* center = [UNUserNotificationCenter currentNotificationCenter];
@@ -10880,7 +10903,9 @@
 #endif
         {
             // Fallback on earlier versions
-            [[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:notification];
+            NSUserNotification *request = (NSUserNotification *)notification;
+            request.identifier = notid;
+            [[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:request];
         }
         return DW_ERROR_NONE;
     }