summaryrefslogtreecommitdiffstats
path: root/macosx/tkMacOSXSysTray.c
diff options
context:
space:
mode:
authormarc_culler <marc.culler@gmail.com>2020-11-01 15:47:50 (GMT)
committermarc_culler <marc.culler@gmail.com>2020-11-01 15:47:50 (GMT)
commitdf042e0afd8158c643945ca8c92dc0718c65c3d0 (patch)
tree84d405ddac00d11c40c616785e780c2911c1e1c1 /macosx/tkMacOSXSysTray.c
parent54fe8b9255f92311fa990d4c2d09e2fc98ee7bd0 (diff)
downloadtk-df042e0afd8158c643945ca8c92dc0718c65c3d0.zip
tk-df042e0afd8158c643945ca8c92dc0718c65c3d0.tar.gz
tk-df042e0afd8158c643945ca8c92dc0718c65c3d0.tar.bz2
Be straightforward - check if the app is signed and use the result to choose the notification API
Diffstat (limited to 'macosx/tkMacOSXSysTray.c')
-rw-r--r--macosx/tkMacOSXSysTray.c41
1 files changed, 12 insertions, 29 deletions
diff --git a/macosx/tkMacOSXSysTray.c b/macosx/tkMacOSXSysTray.c
index 0a06cc7..3ada8ff 100644
--- a/macosx/tkMacOSXSysTray.c
+++ b/macosx/tkMacOSXSysTray.c
@@ -47,7 +47,7 @@
* on systems and the result is saved in a static variable.
*/
-//#define DEBUG
+#define DEBUG
#ifdef DEBUG
/*
@@ -84,14 +84,6 @@ static NSString *TkNotificationCategory;
#if BUILD_TARGET_HAS_NOTIFICATION
/*
- * Flag indicating whether the app is authorized to send notifications via the
- * UserNotification framework. A YES value means that the app is signed AND
- * the user has approved notifications.
- */
-
-static Bool canUseUNNotifications = NO;
-
-/*
* Class declaration for TkStatusItem.
*/
@@ -361,7 +353,6 @@ typedef TkStatusItem** StatusItemInfo;
[center requestAuthorizationWithOptions: options
completionHandler: ^(BOOL granted, NSError* _Nullable error)
{
- canUseUNNotifications = granted;
if (error || granted == NO) {
DEBUG_LOG("Authorization for UNUserNotifications denied\n");
}
@@ -721,22 +712,14 @@ static int SysNotifyObjCmd(
{
NSInteger status = settings.authorizationStatus;
DEBUG_LOG("Reported authorization status is %ld\n", status);
- if (status == UNAuthorizationStatusAuthorized) {
- canUseUNNotifications = YES;
- DEBUG_LOG("Set canUseUNNotifications to YES\n");
- } else {
- canUseUNNotifications = NO;
- DEBUG_LOG("Set canUseUNNotifications to NO\n");
- }
}];
}
-
- if (canUseUNNotifications) {
- DEBUG_LOG("Using the UNUserNotificationCenter\n");
- [UNnotifier postNotificationWithTitle : title message: message];
- } else {
+ if ([NSApp macOSVersion] < 101400 || ![NSApp isSigned]) {
DEBUG_LOG("Using the NSUserNotificationCenter\n");
[NSnotifier postNotificationWithTitle : title message: message];
+ } else {
+ DEBUG_LOG("Using the UNUserNotificationCenter\n");
+ [UNnotifier postNotificationWithTitle : title message: message];
}
#endif //#if BUILD_TARGET_HAS_NOTIFICATION
@@ -790,14 +773,14 @@ MacSystrayInit(Tcl_Interp *interp)
UNnotifier = [[TkUNNotifier alloc] init];
/*
- * Request authorization to use the UserNotification framework.
- * The answer is stored in canUseUNNotifications. If the app code
- * is signed and there are no notification preferences settings for
- * this app, a dialog will be opened to prompt the user to choose
- * settings. Note that the request is asynchronous, so even if the
- * preferences setting exists the result is not available immediately.
+ * Request authorization to use the UserNotification framework. If
+ * the app code is signed and there are no notification preferences
+ * settings for this app, a dialog will be opened to prompt the
+ * user to choose settings. Note that the request is asynchronous,
+ * so even if the preferences setting exists the result is not
+ * available immediately.
*/
-
+
[UNnotifier requestAuthorization];
}
TkNotificationCategory = @"Basic Tk Notification";