Merge branch 'feat-macos-notif-snd' of https://github.com/page-down/kitty
This commit is contained in:
commit
ca0fcada42
@ -2439,7 +2439,7 @@ void _glfwPlatformSetCursor(_GLFWwindow* window, _GLFWcursor* cursor UNUSED)
|
||||
bool _glfwPlatformIsFullscreen(_GLFWwindow* w, unsigned int flags) {
|
||||
NSWindow *window = w->ns.object;
|
||||
bool traditional = !(flags & 1);
|
||||
if (traditional) { if(@available(macOS 10.16, *)) return w->ns.in_traditional_fullscreen; }
|
||||
if (traditional) { if(@available(macOS 11.0, *)) return w->ns.in_traditional_fullscreen; }
|
||||
NSWindowStyleMask sm = [window styleMask];
|
||||
return sm & NSWindowStyleMaskFullScreen;
|
||||
}
|
||||
@ -2450,7 +2450,7 @@ bool _glfwPlatformToggleFullscreen(_GLFWwindow* w, unsigned int flags) {
|
||||
bool traditional = !(flags & 1);
|
||||
NSWindowStyleMask sm = [window styleMask];
|
||||
if (traditional) {
|
||||
if (@available(macOS 10.16, *)) {
|
||||
if (@available(macOS 11.0, *)) {
|
||||
// As of Big Turd NSWindowStyleMaskFullScreen is no longer useable
|
||||
if (!w->ns.in_traditional_fullscreen) {
|
||||
w->ns.pre_full_screen_style_mask = sm;
|
||||
|
||||
@ -222,6 +222,18 @@ cocoa_send_notification(PyObject *self UNUSED, PyObject *args) {
|
||||
@end
|
||||
|
||||
@implementation NotificationDelegate
|
||||
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
|
||||
willPresentNotification:(UNNotification *)notification
|
||||
withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler {
|
||||
UNNotificationPresentationOptions options = UNNotificationPresentationOptionSound;
|
||||
#if MAC_OS_X_VERSION_MAX_ALLOWED < 110000
|
||||
options |= UNNotificationPresentationOptionAlert;
|
||||
#else
|
||||
options |= UNNotificationPresentationOptionList | UNNotificationPresentationOptionBanner;
|
||||
#endif
|
||||
completionHandler(options);
|
||||
}
|
||||
|
||||
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
|
||||
didReceiveNotificationResponse:(UNNotificationResponse *)response
|
||||
withCompletionHandler:(void (^)(void))completionHandler {
|
||||
@ -247,6 +259,7 @@ schedule_notification(const char *identifier, const char *title, const char *bod
|
||||
if (title) content.title = @(title);
|
||||
if (body) content.body = @(body);
|
||||
if (subtitle) content.subtitle = @(subtitle);
|
||||
content.sound = [UNNotificationSound defaultSound];
|
||||
// Deliver the notification
|
||||
static unsigned long counter = 1;
|
||||
UNNotificationRequest* request = [
|
||||
@ -306,7 +319,9 @@ cocoa_send_notification(PyObject *self UNUSED, PyObject *args) {
|
||||
if (!center.delegate) center.delegate = [[NotificationDelegate alloc] init];
|
||||
queue_notification(identifier, title, body, subtitle);
|
||||
|
||||
[center requestAuthorizationWithOptions:(UNAuthorizationOptionAlert)
|
||||
// The badge permission needs to be requested as well, even though it is not used,
|
||||
// otherwise macOS refuses to show the preference checkbox for enable/disable notification sound.
|
||||
[center requestAuthorizationWithOptions:(UNAuthorizationOptionAlert | UNAuthorizationOptionSound | UNAuthorizationOptionBadge)
|
||||
completionHandler:^(BOOL granted, NSError * _Nullable error) {
|
||||
if (error != nil) {
|
||||
log_error("Failed to request permission for showing notification: %s", [[error localizedDescription] UTF8String]);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user