From 9b19f300fe7c492ce86e3c6c03a5e1ad8f6125fc Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 30 Jul 2024 07:39:53 +0530 Subject: [PATCH] Drop support for building without UserNotifications Trying to maintain the two code paths is too much effort given all the new features being added to notifications. --- kitty/cocoa_window.m | 53 +------------------------------------------- setup.py | 2 +- 2 files changed, 2 insertions(+), 53 deletions(-) diff --git a/kitty/cocoa_window.m b/kitty/cocoa_window.m index f3366b178..b549bd5c6 100644 --- a/kitty/cocoa_window.m +++ b/kitty/cocoa_window.m @@ -12,9 +12,7 @@ #include #include #include -#ifndef KITTY_USE_DEPRECATED_MACOS_NOTIFICATION_API #include -#endif #include // Needed for _NSGetProgname @@ -368,51 +366,6 @@ do_notification_callback(NSString *identifier, const char *event) { } -#ifdef KITTY_USE_DEPRECATED_MACOS_NOTIFICATION_API - -@interface NotificationDelegate : NSObject -@end - -@implementation NotificationDelegate - - (void)userNotificationCenter:(NSUserNotificationCenter *)center - didDeliverNotification:(NSUserNotification *)notification { - (void)(center); (void)(notification); - } - - - (BOOL) userNotificationCenter:(NSUserNotificationCenter *)center - shouldPresentNotification:(NSUserNotification *)notification { - (void)(center); (void)(notification); - return YES; - } - - - (void) userNotificationCenter:(NSUserNotificationCenter *)center - didActivateNotification:(NSUserNotification *)notification { - (void)(center); (void)(notification); - do_notification_callback(notification.userInfo[@"user_id"], "activated"); - } - } -@end - -static PyObject* -cocoa_send_notification(PyObject *self UNUSED, PyObject *args) { - char *identifier = NULL, *title = NULL, *informativeText = NULL, *subtitle = NULL; int urgency = 1; - if (!PyArg_ParseTuple(args, "zsz|zi", &identifier, &title, &informativeText, &subtitle, &urgency)) return NULL; - NSUserNotificationCenter *center = [NSUserNotificationCenter defaultUserNotificationCenter]; - if (!center) {PyErr_SetString(PyExc_RuntimeError, "Failed to get the user notification center"); return NULL; } - if (!center.delegate) center.delegate = [[NotificationDelegate alloc] init]; - NSUserNotification *n = [NSUserNotification new]; - if (title) n.title = @(title); - if (subtitle) n.subtitle = @(subtitle); - if (informativeText) n.informativeText = @(informativeText); - if (identifier) { - n.userInfo = @{@"user_id": @(identifier)}; - } - [center deliverNotification:n]; - Py_RETURN_NONE; -} - -#else - @interface NotificationDelegate : NSObject @end @@ -619,8 +572,6 @@ cocoa_send_notification(PyObject *self UNUSED, PyObject *args) { Py_RETURN_NONE; } -#endif - @interface ServiceProvider : NSObject @end @@ -1073,12 +1024,10 @@ cleanup(void) { if (beep_sound) [beep_sound release]; beep_sound = nil; -#ifndef KITTY_USE_DEPRECATED_MACOS_NOTIFICATION_API drain_pending_notifications(NO); free(notification_queue.notifications); notification_queue.notifications = NULL; notification_queue.capacity = 0; -#endif } // autoreleasepool } @@ -1109,7 +1058,7 @@ cocoa_set_uncaught_exception_handler(void) { static PyMethodDef module_methods[] = { {"cocoa_get_lang", (PyCFunction)cocoa_get_lang, METH_NOARGS, ""}, {"cocoa_set_global_shortcut", (PyCFunction)cocoa_set_global_shortcut, METH_VARARGS, ""}, - {"cocoa_send_notification", (PyCFunction)cocoa_send_notification, METH_VARARGS, ""}, + {"cocoa_send_notification", (PyCFunction)(void(*)(void))cocoa_send_notification, METH_VARARGS, ""}, {"cocoa_remove_delivered_notification", (PyCFunction)cocoa_remove_delivered_notification, METH_O, ""}, {"cocoa_live_delivered_notifications", (PyCFunction)cocoa_live_delivered_notifications, METH_NOARGS, ""}, {"cocoa_set_notification_activated_callback", (PyCFunction)set_notification_activated_callback, METH_O, ""}, diff --git a/setup.py b/setup.py index ff317434f..c1982189c 100755 --- a/setup.py +++ b/setup.py @@ -626,7 +626,7 @@ def kitty_env(args: Options) -> Env: if user_notifications_framework: platform_libs.extend(shlex.split(user_notifications_framework)) else: - cppflags.append('-DKITTY_USE_DEPRECATED_MACOS_NOTIFICATION_API') + raise SystemExit('UserNotifications framework missing') # Apple deprecated OpenGL in Mojave (10.14) silence the endless # warnings about it cppflags.append('-DGL_SILENCE_DEPRECATION')