From a1b40cc8f52b24fe5919dfb081b34ccb1437d5f1 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 13 Mar 2024 11:43:38 +0530 Subject: [PATCH] Handle exception raised by Cocoa runtime when trying to get user notification center from a non-bundled executable --- kitty/cocoa_window.m | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/kitty/cocoa_window.m b/kitty/cocoa_window.m index 0045d5118..f70d7defc 100644 --- a/kitty/cocoa_window.m +++ b/kitty/cocoa_window.m @@ -441,7 +441,13 @@ - (void)userNotificationCenter:(UNUserNotificationCenter *)center static void schedule_notification(const char *identifier, const char *title, const char *body, const char *subtitle) { - UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; + UNUserNotificationCenter *center = nil; + @try { + center = [UNUserNotificationCenter currentNotificationCenter]; + } @catch (NSException *e) { + log_error("Failed to get current UNUserNotificationCenter object with error: %s (%s)", + [[e name] UTF8String], [[e reason] UTF8String]); + } if (!center) return; // Configure the notification's payload. UNMutableNotificationContent* content = [[UNMutableNotificationContent alloc] init]; @@ -503,7 +509,13 @@ - (void)userNotificationCenter:(UNUserNotificationCenter *)center char *identifier = NULL, *title = NULL, *body = NULL, *subtitle = NULL; if (!PyArg_ParseTuple(args, "zsz|z", &identifier, &title, &body, &subtitle)) return NULL; - UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; + UNUserNotificationCenter *center = nil; + @try { + center = [UNUserNotificationCenter currentNotificationCenter]; + } @catch (NSException *e) { + log_error("Failed to get current UNUserNotificationCenter object with error: %s (%s)", + [[e name] UTF8String], [[e reason] UTF8String]); + } if (!center) Py_RETURN_NONE; if (!center.delegate) center.delegate = [[NotificationDelegate alloc] init]; queue_notification(identifier, title, body, subtitle);