Mercurial > dwindows
comparison mac/dw.m @ 2074:1a196ada0bc9
Mac: Add safety checks. Check bundleIdentifier is not nil before calling
Notification APIs on Mojave. This will abort if the application ID is not set.
Add basic script for self-signing the dwtest application if possible.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Thu, 21 May 2020 14:17:36 +0000 |
parents | cf70a52f702e |
children | c020ad267ae2 |
comparison
equal
deleted
inserted
replaced
2073:cf70a52f702e | 2074:1a196ada0bc9 |
---|---|
1435 return NSTerminateNow; | 1435 return NSTerminateNow; |
1436 } | 1436 } |
1437 -(void)applicationDidFinishLaunching:(NSNotification *)aNotification | 1437 -(void)applicationDidFinishLaunching:(NSNotification *)aNotification |
1438 { | 1438 { |
1439 #ifdef BUILDING_FOR_MOJAVE | 1439 #ifdef BUILDING_FOR_MOJAVE |
1440 if (!@available(macOS 10.14, *)) | 1440 if (@available(macOS 10.14, *)) {} else |
1441 #endif | 1441 #endif |
1442 { | 1442 { |
1443 NSUserNotificationCenter* unc = [NSUserNotificationCenter defaultUserNotificationCenter]; | 1443 NSUserNotificationCenter* unc = [NSUserNotificationCenter defaultUserNotificationCenter]; |
1444 unc.delegate = self; | 1444 unc.delegate = self; |
1445 } | 1445 } |
10764 | 10764 |
10765 #ifdef BUILDING_FOR_MOJAVE | 10765 #ifdef BUILDING_FOR_MOJAVE |
10766 // Configure the notification's payload. | 10766 // Configure the notification's payload. |
10767 if (@available(macOS 10.14, *)) | 10767 if (@available(macOS 10.14, *)) |
10768 { | 10768 { |
10769 UNMutableNotificationContent* notification = [[UNMutableNotificationContent alloc] init]; | 10769 if([[NSBundle mainBundle] bundleIdentifier] != nil) |
10770 | 10770 { |
10771 if(notification) | 10771 UNMutableNotificationContent* notification = [[UNMutableNotificationContent alloc] init]; |
10772 { | 10772 |
10773 notification.title = [NSString stringWithUTF8String:title]; | 10773 if(notification) |
10774 if(description) | 10774 { |
10775 notification.body = [NSString stringWithUTF8String:outbuf]; | 10775 notification.title = [NSString stringWithUTF8String:title]; |
10776 retval = notification; | 10776 if(description) |
10777 notification.body = [NSString stringWithUTF8String:outbuf]; | |
10778 retval = notification; | |
10779 } | |
10777 } | 10780 } |
10778 } | 10781 } |
10779 else | 10782 else |
10780 #endif | 10783 #endif |
10781 { | 10784 { |
10811 { | 10814 { |
10812 #ifdef BUILDING_FOR_MOJAVE | 10815 #ifdef BUILDING_FOR_MOJAVE |
10813 // Schedule the notification. | 10816 // Schedule the notification. |
10814 if (@available(macOS 10.14, *)) | 10817 if (@available(macOS 10.14, *)) |
10815 { | 10818 { |
10816 UNMutableNotificationContent *content = (UNMutableNotificationContent *)notification; | 10819 if([[NSBundle mainBundle] bundleIdentifier] != nil) |
10817 NSString *notid = [NSString stringWithFormat:@"dw-notification-%llu", (unsigned long long)notification]; | 10820 { |
10818 UNNotificationRequest* request = [UNNotificationRequest requestWithIdentifier:notid | 10821 UNMutableNotificationContent *content = (UNMutableNotificationContent *)notification; |
10819 content:content trigger:nil]; | 10822 NSString *notid = [NSString stringWithFormat:@"dw-notification-%llu", (unsigned long long)notification]; |
10820 | 10823 UNNotificationRequest* request = [UNNotificationRequest requestWithIdentifier:notid |
10821 UNUserNotificationCenter* center = [UNUserNotificationCenter currentNotificationCenter]; | 10824 content:content trigger:nil]; |
10822 [center addNotificationRequest:request withCompletionHandler:^(NSError * _Nullable error) { | 10825 |
10823 _event_handler(notification, nil, 8); | 10826 UNUserNotificationCenter* center = [UNUserNotificationCenter currentNotificationCenter]; |
10824 }]; | 10827 [center addNotificationRequest:request withCompletionHandler:^(NSError * _Nullable error) { |
10828 _event_handler(notification, nil, 8); | |
10829 }]; | |
10830 } | |
10825 } | 10831 } |
10826 else | 10832 else |
10827 #endif | 10833 #endif |
10828 { | 10834 { |
10829 // Fallback on earlier versions | 10835 // Fallback on earlier versions |
12100 DWObj = [[DWObject alloc] init]; | 12106 DWObj = [[DWObject alloc] init]; |
12101 DWDefaultFont = nil; | 12107 DWDefaultFont = nil; |
12102 #ifdef BUILDING_FOR_MOJAVE | 12108 #ifdef BUILDING_FOR_MOJAVE |
12103 if (@available(macOS 10.14, *)) | 12109 if (@available(macOS 10.14, *)) |
12104 { | 12110 { |
12105 UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; | 12111 if([[NSBundle mainBundle] bundleIdentifier] != nil) |
12106 if(center) | 12112 { |
12107 { | 12113 UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; |
12108 [center requestAuthorizationWithOptions:UNAuthorizationOptionAlert|UNAuthorizationOptionSound | 12114 if(center) |
12109 completionHandler:^(BOOL granted, NSError * _Nullable error) { | 12115 { |
12110 if (!granted) { | 12116 [center requestAuthorizationWithOptions:UNAuthorizationOptionAlert|UNAuthorizationOptionSound |
12111 NSLog(@"WARNING: Unable to get notification permission."); | 12117 completionHandler:^(BOOL granted, NSError * _Nullable error) { |
12112 } | 12118 if (!granted) { |
12113 }]; | 12119 NSLog(@"WARNING: Unable to get notification permission. %@", error.localizedDescription); |
12120 } | |
12121 }]; | |
12122 } | |
12114 } | 12123 } |
12115 } | 12124 } |
12116 _DWDirtyDrawables = [[NSMutableArray alloc] init]; | 12125 _DWDirtyDrawables = [[NSMutableArray alloc] init]; |
12117 #else | 12126 #else |
12118 /* Create mutexes for thread safety */ | 12127 /* Create mutexes for thread safety */ |