From fdcc623cf14fda96cce34e26c67cd9515cf4c4f5 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Thu, 13 Apr 2023 17:00:57 +0800 Subject: [PATCH 1/5] Constify object pointers in systray.mm Signed-off-by: Claudio Cambra --- src/gui/systray.mm | 70 +++++++++++++++++++++++----------------------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/src/gui/systray.mm b/src/gui/systray.mm index d9e5d03d0f..313c262868 100644 --- a/src/gui/systray.mm +++ b/src/gui/systray.mm @@ -26,7 +26,7 @@ void sendTalkReply(UNNotificationResponse *response, UNNotificationContent* cont return; } - UNTextInputNotificationResponse *textInputResponse = (UNTextInputNotificationResponse*)response; + UNTextInputNotificationResponse * const textInputResponse = (UNTextInputNotificationResponse*)response; if (!textInputResponse) { qCWarning(lcMacSystray()) << "Notification response was not a text input response." @@ -34,10 +34,10 @@ void sendTalkReply(UNNotificationResponse *response, UNNotificationContent* cont return; } - NSString *reply = textInputResponse.userText; - NSString *token = [content.userInfo objectForKey:@"token"]; - NSString *account = [content.userInfo objectForKey:@"account"]; - NSString *replyTo = [content.userInfo objectForKey:@"replyTo"]; + NSString * const reply = textInputResponse.userText; + NSString * const token = [content.userInfo objectForKey:@"token"]; + NSString * const account = [content.userInfo objectForKey:@"account"]; + NSString * const replyTo = [content.userInfo objectForKey:@"replyTo"]; const auto qReply = QString::fromNSString(reply); const auto qReplyTo = QString::fromNSString(replyTo); @@ -88,7 +88,7 @@ void sendTalkReply(UNNotificationResponse *response, UNNotificationContent* cont { qCDebug(lcMacSystray()) << "Received notification with category identifier:" << response.notification.request.content.categoryIdentifier << "and action identifier" << response.actionIdentifier; - UNNotificationContent* content = response.notification.request.content; + UNNotificationContent * const content = response.notification.request.content; if ([content.categoryIdentifier isEqualToString:@"UPDATE"]) { if ([response.actionIdentifier isEqualToString:@"DOWNLOAD_ACTION"] || [response.actionIdentifier isEqualToString:UNNotificationDefaultActionIdentifier]) { @@ -112,7 +112,7 @@ namespace OCC { double menuBarThickness() { - const NSMenu *mainMenu = [[NSApplication sharedApplication] mainMenu]; + NSMenu * const mainMenu = [[NSApplication sharedApplication] mainMenu]; if (mainMenu == nil) { // Return this educated guess if something goes wrong. @@ -127,39 +127,39 @@ double menuBarThickness() // TODO: Get this to actually check for permissions bool canOsXSendUserNotification() { - UNUserNotificationCenter* center = [UNUserNotificationCenter currentNotificationCenter]; + UNUserNotificationCenter * const center = [UNUserNotificationCenter currentNotificationCenter]; return center != nil; } void registerNotificationCategories(const QString &localisedDownloadString) { - UNNotificationCategory* generalCategory = [UNNotificationCategory + UNNotificationCategory * const generalCategory = [UNNotificationCategory categoryWithIdentifier:@"GENERAL" actions:@[] intentIdentifiers:@[] options:UNNotificationCategoryOptionCustomDismissAction]; // Create the custom actions for update notifications. - UNNotificationAction* downloadAction = [UNNotificationAction + UNNotificationAction * const downloadAction = [UNNotificationAction actionWithIdentifier:@"DOWNLOAD_ACTION" title:localisedDownloadString.toNSString() options:UNNotificationActionOptionNone]; // Create the category with the custom actions. - UNNotificationCategory* updateCategory = [UNNotificationCategory + UNNotificationCategory * const updateCategory = [UNNotificationCategory categoryWithIdentifier:@"UPDATE" actions:@[downloadAction] intentIdentifiers:@[] options:UNNotificationCategoryOptionNone]; // Create the custom action for talk notifications - UNTextInputNotificationAction* talkReplyAction = [UNTextInputNotificationAction + UNTextInputNotificationAction * const talkReplyAction = [UNTextInputNotificationAction actionWithIdentifier:@"TALK_REPLY_ACTION" title:QObject::tr("Reply").toNSString() options:UNNotificationActionOptionNone textInputButtonTitle:QObject::tr("Reply").toNSString() textInputPlaceholder:QObject::tr("Send a Nextcloud Talk reply").toNSString()]; - UNNotificationCategory* talkReplyCategory = [UNNotificationCategory + UNNotificationCategory * const talkReplyCategory = [UNNotificationCategory categoryWithIdentifier:@"TALK_MESSAGE" actions:@[talkReplyAction] intentIdentifiers:@[] @@ -170,7 +170,7 @@ void registerNotificationCategories(const QString &localisedDownloadString) { void checkNotificationAuth(MacNotificationAuthorizationOptions additionalAuthOption) { - UNUserNotificationCenter* center = [UNUserNotificationCenter currentNotificationCenter]; + UNUserNotificationCenter * const center = [UNUserNotificationCenter currentNotificationCenter]; UNAuthorizationOptions authOptions = UNAuthorizationOptionAlert + UNAuthorizationOptionSound; if(additionalAuthOption == MacNotificationAuthorizationOptions::Provisional) { @@ -180,7 +180,7 @@ void checkNotificationAuth(MacNotificationAuthorizationOptions additionalAuthOpt [center requestAuthorizationWithOptions:(authOptions) completionHandler:^(BOOL granted, NSError * _Nullable error) { // Enable or disable features based on authorization. - if(granted) { + if (granted) { qCDebug(lcMacSystray) << "Authorization for notifications has been granted, can display notifications."; } else { qCDebug(lcMacSystray) << "Authorization for notifications not granted."; @@ -194,7 +194,7 @@ void checkNotificationAuth(MacNotificationAuthorizationOptions additionalAuthOpt void setUserNotificationCenterDelegate() { - UNUserNotificationCenter* center = [UNUserNotificationCenter currentNotificationCenter]; + UNUserNotificationCenter * const center = [UNUserNotificationCenter currentNotificationCenter]; static dispatch_once_t once; dispatch_once(&once, ^{ @@ -205,7 +205,7 @@ void setUserNotificationCenterDelegate() UNMutableNotificationContent* basicNotificationContent(const QString &title, const QString &message) { - UNMutableNotificationContent* content = [[UNMutableNotificationContent alloc] init]; + UNMutableNotificationContent * const content = [[UNMutableNotificationContent alloc] init]; content.title = title.toNSString(); content.body = message.toNSString(); content.sound = [UNNotificationSound defaultSound]; @@ -215,36 +215,36 @@ UNMutableNotificationContent* basicNotificationContent(const QString &title, con void sendOsXUserNotification(const QString &title, const QString &message) { - UNUserNotificationCenter* center = [UNUserNotificationCenter currentNotificationCenter]; + UNUserNotificationCenter * const center = [UNUserNotificationCenter currentNotificationCenter]; checkNotificationAuth(); - UNMutableNotificationContent* content = basicNotificationContent(title, message); + UNMutableNotificationContent * const content = basicNotificationContent(title, message); content.categoryIdentifier = @"GENERAL"; - UNTimeIntervalNotificationTrigger* trigger = [UNTimeIntervalNotificationTrigger triggerWithTimeInterval:1 repeats: NO]; - UNNotificationRequest* request = [UNNotificationRequest requestWithIdentifier:@"NCUserNotification" content:content trigger:trigger]; + UNTimeIntervalNotificationTrigger * const trigger = [UNTimeIntervalNotificationTrigger triggerWithTimeInterval:1 repeats: NO]; + UNNotificationRequest * const request = [UNNotificationRequest requestWithIdentifier:@"NCUserNotification" content:content trigger:trigger]; [center addNotificationRequest:request withCompletionHandler:nil]; } void sendOsXUpdateNotification(const QString &title, const QString &message, const QUrl &webUrl) { - UNUserNotificationCenter* center = [UNUserNotificationCenter currentNotificationCenter]; + UNUserNotificationCenter * const center = [UNUserNotificationCenter currentNotificationCenter]; checkNotificationAuth(); - UNMutableNotificationContent* content = basicNotificationContent(title, message); + UNMutableNotificationContent * const content = basicNotificationContent(title, message); content.categoryIdentifier = @"UPDATE"; content.userInfo = [NSDictionary dictionaryWithObject:[webUrl.toNSURL() absoluteString] forKey:@"webUrl"]; - UNTimeIntervalNotificationTrigger* trigger = [UNTimeIntervalNotificationTrigger triggerWithTimeInterval:1 repeats: NO]; - UNNotificationRequest* request = [UNNotificationRequest requestWithIdentifier:@"NCUpdateNotification" content:content trigger:trigger]; + UNTimeIntervalNotificationTrigger * const trigger = [UNTimeIntervalNotificationTrigger triggerWithTimeInterval:1 repeats: NO]; + UNNotificationRequest * const request = [UNNotificationRequest requestWithIdentifier:@"NCUpdateNotification" content:content trigger:trigger]; [center addNotificationRequest:request withCompletionHandler:nil]; } void sendOsXTalkNotification(const QString &title, const QString &message, const QString &token, const QString &replyTo, const AccountStatePtr accountState) { - UNUserNotificationCenter* center = [UNUserNotificationCenter currentNotificationCenter]; + UNUserNotificationCenter * const center = [UNUserNotificationCenter currentNotificationCenter]; checkNotificationAuth(); if (!accountState || !accountState->account()) { @@ -252,24 +252,24 @@ void sendOsXTalkNotification(const QString &title, const QString &message, const return; } - NSString *accountNS = accountState->account()->displayName().toNSString(); - NSString *tokenNS = token.toNSString(); - NSString *replyToNS = replyTo.toNSString(); + NSString * const accountNS = accountState->account()->displayName().toNSString(); + NSString * const tokenNS = token.toNSString(); + NSString * const replyToNS = replyTo.toNSString(); - UNMutableNotificationContent* content = basicNotificationContent(title, message); + UNMutableNotificationContent * const content = basicNotificationContent(title, message); content.categoryIdentifier = @"TALK_MESSAGE"; content.userInfo = [NSDictionary dictionaryWithObjects:@[accountNS, tokenNS, replyToNS] forKeys:@[@"account", @"token", @"replyTo"]]; - UNTimeIntervalNotificationTrigger* trigger = [UNTimeIntervalNotificationTrigger triggerWithTimeInterval:1 repeats: NO]; - UNNotificationRequest* request = [UNNotificationRequest requestWithIdentifier:@"NCTalkMessageNotification" content:content trigger:trigger]; + UNTimeIntervalNotificationTrigger * const trigger = [UNTimeIntervalNotificationTrigger triggerWithTimeInterval:1 repeats: NO]; + UNNotificationRequest * const request = [UNNotificationRequest requestWithIdentifier:@"NCTalkMessageNotification" content:content trigger:trigger]; [center addNotificationRequest:request withCompletionHandler:nil]; } void setTrayWindowLevelAndVisibleOnAllSpaces(QWindow *window) { - NSView *nativeView = (NSView *)window->winId(); - NSWindow *nativeWindow = (NSWindow *)[nativeView window]; + NSView * const nativeView = (NSView *)window->winId(); + NSWindow * const nativeWindow = (NSWindow *)[nativeView window]; [nativeWindow setCollectionBehavior:NSWindowCollectionBehaviorCanJoinAllSpaces | NSWindowCollectionBehaviorIgnoresCycle | NSWindowCollectionBehaviorTransient]; [nativeWindow setLevel:NSMainMenuWindowLevel]; @@ -277,7 +277,7 @@ void setTrayWindowLevelAndVisibleOnAllSpaces(QWindow *window) bool osXInDarkMode() { - NSString *osxMode = [[NSUserDefaults standardUserDefaults] stringForKey:@"AppleInterfaceStyle"]; + NSString * const osxMode = [[NSUserDefaults standardUserDefaults] stringForKey:@"AppleInterfaceStyle"]; return [osxMode containsString:@"Dark"]; } From 5ecfa96d9c0ccc9d2137d1300fece1bad2a79e6a Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Thu, 13 Apr 2023 17:06:51 +0800 Subject: [PATCH 2/5] Use const auto for C++ variables in systray.mm Signed-off-by: Claudio Cambra --- src/gui/systray.mm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gui/systray.mm b/src/gui/systray.mm index 313c262868..fe6600c66e 100644 --- a/src/gui/systray.mm +++ b/src/gui/systray.mm @@ -58,7 +58,7 @@ void sendTalkReply(UNNotificationResponse *response, UNNotificationContent* cont << "Token:" << qToken << "Account:" << qAccount; - QPointer talkReply = new OCC::TalkReply(accountState.data(), OCC::Systray::instance()); + const auto talkReply = QSharedPointer(new OCC::TalkReply(accountState.data(), OCC::Systray::instance())); talkReply->sendReplyMessage(qToken, qReply, qReplyTo); } @@ -185,7 +185,7 @@ void checkNotificationAuth(MacNotificationAuthorizationOptions additionalAuthOpt } else { qCDebug(lcMacSystray) << "Authorization for notifications not granted."; if(error) { - QString errorDescription([error.localizedDescription UTF8String]); + const auto errorDescription = QString::fromNSString(error.localizedDescription); qCDebug(lcMacSystray) << "Error from notification center: " << errorDescription; } } From 91d5d9dc02e55337cebcba6595b4048249dd3d79 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Thu, 13 Apr 2023 17:14:11 +0800 Subject: [PATCH 3/5] Modernise property accessing in systray.mm Signed-off-by: Claudio Cambra --- src/gui/systray.mm | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/gui/systray.mm b/src/gui/systray.mm index fe6600c66e..e8f012c709 100644 --- a/src/gui/systray.mm +++ b/src/gui/systray.mm @@ -118,7 +118,7 @@ double menuBarThickness() // Return this educated guess if something goes wrong. // As of macOS 12.4 this will always return 22, even on notched Macbooks. qCWarning(lcMacSystray) << "Got nil for main menu. Going with reasonable menu bar height guess."; - return [[NSStatusBar systemStatusBar] thickness]; + return NSStatusBar.systemStatusBar.thickness; } return mainMenu.menuBarHeight; @@ -127,7 +127,7 @@ double menuBarThickness() // TODO: Get this to actually check for permissions bool canOsXSendUserNotification() { - UNUserNotificationCenter * const center = [UNUserNotificationCenter currentNotificationCenter]; + UNUserNotificationCenter * const center = UNUserNotificationCenter.currentNotificationCenter; return center != nil; } @@ -165,12 +165,12 @@ void registerNotificationCategories(const QString &localisedDownloadString) { intentIdentifiers:@[] options:UNNotificationCategoryOptionNone]; - [[UNUserNotificationCenter currentNotificationCenter] setNotificationCategories:[NSSet setWithObjects:generalCategory, updateCategory, talkReplyCategory, nil]]; + [UNUserNotificationCenter.currentNotificationCenter setNotificationCategories:[NSSet setWithObjects:generalCategory, updateCategory, talkReplyCategory, nil]]; } void checkNotificationAuth(MacNotificationAuthorizationOptions additionalAuthOption) { - UNUserNotificationCenter * const center = [UNUserNotificationCenter currentNotificationCenter]; + UNUserNotificationCenter * const center = UNUserNotificationCenter.currentNotificationCenter; UNAuthorizationOptions authOptions = UNAuthorizationOptionAlert + UNAuthorizationOptionSound; if(additionalAuthOption == MacNotificationAuthorizationOptions::Provisional) { @@ -194,7 +194,7 @@ void checkNotificationAuth(MacNotificationAuthorizationOptions additionalAuthOpt void setUserNotificationCenterDelegate() { - UNUserNotificationCenter * const center = [UNUserNotificationCenter currentNotificationCenter]; + UNUserNotificationCenter * const center = UNUserNotificationCenter.currentNotificationCenter; static dispatch_once_t once; dispatch_once(&once, ^{ @@ -215,13 +215,13 @@ UNMutableNotificationContent* basicNotificationContent(const QString &title, con void sendOsXUserNotification(const QString &title, const QString &message) { - UNUserNotificationCenter * const center = [UNUserNotificationCenter currentNotificationCenter]; + UNUserNotificationCenter * const center = UNUserNotificationCenter.currentNotificationCenter; checkNotificationAuth(); UNMutableNotificationContent * const content = basicNotificationContent(title, message); content.categoryIdentifier = @"GENERAL"; - UNTimeIntervalNotificationTrigger * const trigger = [UNTimeIntervalNotificationTrigger triggerWithTimeInterval:1 repeats: NO]; + UNTimeIntervalNotificationTrigger * const trigger = [UNTimeIntervalNotificationTrigger triggerWithTimeInterval:1 repeats:NO]; UNNotificationRequest * const request = [UNNotificationRequest requestWithIdentifier:@"NCUserNotification" content:content trigger:trigger]; [center addNotificationRequest:request withCompletionHandler:nil]; @@ -229,14 +229,14 @@ void sendOsXUserNotification(const QString &title, const QString &message) void sendOsXUpdateNotification(const QString &title, const QString &message, const QUrl &webUrl) { - UNUserNotificationCenter * const center = [UNUserNotificationCenter currentNotificationCenter]; + UNUserNotificationCenter * const center = UNUserNotificationCenter.currentNotificationCenter; checkNotificationAuth(); UNMutableNotificationContent * const content = basicNotificationContent(title, message); content.categoryIdentifier = @"UPDATE"; content.userInfo = [NSDictionary dictionaryWithObject:[webUrl.toNSURL() absoluteString] forKey:@"webUrl"]; - UNTimeIntervalNotificationTrigger * const trigger = [UNTimeIntervalNotificationTrigger triggerWithTimeInterval:1 repeats: NO]; + UNTimeIntervalNotificationTrigger * const trigger = [UNTimeIntervalNotificationTrigger triggerWithTimeInterval:1 repeats:NO]; UNNotificationRequest * const request = [UNNotificationRequest requestWithIdentifier:@"NCUpdateNotification" content:content trigger:trigger]; [center addNotificationRequest:request withCompletionHandler:nil]; @@ -244,7 +244,7 @@ void sendOsXUpdateNotification(const QString &title, const QString &message, con void sendOsXTalkNotification(const QString &title, const QString &message, const QString &token, const QString &replyTo, const AccountStatePtr accountState) { - UNUserNotificationCenter * const center = [UNUserNotificationCenter currentNotificationCenter]; + UNUserNotificationCenter * const center = UNUserNotificationCenter.currentNotificationCenter; checkNotificationAuth(); if (!accountState || !accountState->account()) { @@ -269,7 +269,7 @@ void sendOsXTalkNotification(const QString &title, const QString &message, const void setTrayWindowLevelAndVisibleOnAllSpaces(QWindow *window) { NSView * const nativeView = (NSView *)window->winId(); - NSWindow * const nativeWindow = (NSWindow *)[nativeView window]; + NSWindow * const nativeWindow = (NSWindow *)(nativeView.window); [nativeWindow setCollectionBehavior:NSWindowCollectionBehaviorCanJoinAllSpaces | NSWindowCollectionBehaviorIgnoresCycle | NSWindowCollectionBehaviorTransient]; [nativeWindow setLevel:NSMainMenuWindowLevel]; @@ -277,7 +277,7 @@ void setTrayWindowLevelAndVisibleOnAllSpaces(QWindow *window) bool osXInDarkMode() { - NSString * const osxMode = [[NSUserDefaults standardUserDefaults] stringForKey:@"AppleInterfaceStyle"]; + NSString * const osxMode = [NSUserDefaults.standardUserDefaults stringForKey:@"AppleInterfaceStyle"]; return [osxMode containsString:@"Dark"]; } From 08098b8d926c06f179d055c0e6e8e47a3e186809 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Thu, 13 Apr 2023 17:26:03 +0800 Subject: [PATCH 4/5] Fix spacing and indentation in systray.mm Signed-off-by: Claudio Cambra --- src/gui/systray.mm | 71 +++++++++++++++++++++++----------------------- 1 file changed, 35 insertions(+), 36 deletions(-) diff --git a/src/gui/systray.mm b/src/gui/systray.mm index e8f012c709..f17372baf7 100644 --- a/src/gui/systray.mm +++ b/src/gui/systray.mm @@ -83,8 +83,8 @@ void sendTalkReply(UNNotificationResponse *response, UNNotificationContent* cont } - (void)userNotificationCenter:(UNUserNotificationCenter *)center - didReceiveNotificationResponse:(UNNotificationResponse *)response - withCompletionHandler:(void (^)(void))completionHandler +didReceiveNotificationResponse:(UNNotificationResponse *)response + withCompletionHandler:(void (^)(void))completionHandler { qCDebug(lcMacSystray()) << "Received notification with category identifier:" << response.notification.request.content.categoryIdentifier << "and action identifier" << response.actionIdentifier; @@ -133,37 +133,37 @@ bool canOsXSendUserNotification() void registerNotificationCategories(const QString &localisedDownloadString) { UNNotificationCategory * const generalCategory = [UNNotificationCategory - categoryWithIdentifier:@"GENERAL" - actions:@[] - intentIdentifiers:@[] - options:UNNotificationCategoryOptionCustomDismissAction]; + categoryWithIdentifier:@"GENERAL" + actions:@[] + intentIdentifiers:@[] + options:UNNotificationCategoryOptionCustomDismissAction]; // Create the custom actions for update notifications. UNNotificationAction * const downloadAction = [UNNotificationAction - actionWithIdentifier:@"DOWNLOAD_ACTION" - title:localisedDownloadString.toNSString() - options:UNNotificationActionOptionNone]; + actionWithIdentifier:@"DOWNLOAD_ACTION" + title:localisedDownloadString.toNSString() + options:UNNotificationActionOptionNone]; // Create the category with the custom actions. UNNotificationCategory * const updateCategory = [UNNotificationCategory - categoryWithIdentifier:@"UPDATE" - actions:@[downloadAction] - intentIdentifiers:@[] - options:UNNotificationCategoryOptionNone]; + categoryWithIdentifier:@"UPDATE" + actions:@[downloadAction] + intentIdentifiers:@[] + options:UNNotificationCategoryOptionNone]; // Create the custom action for talk notifications UNTextInputNotificationAction * const talkReplyAction = [UNTextInputNotificationAction - actionWithIdentifier:@"TALK_REPLY_ACTION" - title:QObject::tr("Reply").toNSString() - options:UNNotificationActionOptionNone - textInputButtonTitle:QObject::tr("Reply").toNSString() - textInputPlaceholder:QObject::tr("Send a Nextcloud Talk reply").toNSString()]; + actionWithIdentifier:@"TALK_REPLY_ACTION" + title:QObject::tr("Reply").toNSString() + options:UNNotificationActionOptionNone + textInputButtonTitle:QObject::tr("Reply").toNSString() + textInputPlaceholder:QObject::tr("Send a Nextcloud Talk reply").toNSString()]; UNNotificationCategory * const talkReplyCategory = [UNNotificationCategory - categoryWithIdentifier:@"TALK_MESSAGE" - actions:@[talkReplyAction] - intentIdentifiers:@[] - options:UNNotificationCategoryOptionNone]; + categoryWithIdentifier:@"TALK_MESSAGE" + actions:@[talkReplyAction] + intentIdentifiers:@[] + options:UNNotificationCategoryOptionNone]; [UNUserNotificationCenter.currentNotificationCenter setNotificationCategories:[NSSet setWithObjects:generalCategory, updateCategory, talkReplyCategory, nil]]; } @@ -177,18 +177,17 @@ void checkNotificationAuth(MacNotificationAuthorizationOptions additionalAuthOpt authOptions += UNAuthorizationOptionProvisional; } - [center requestAuthorizationWithOptions:(authOptions) - completionHandler:^(BOOL granted, NSError * _Nullable error) { - // Enable or disable features based on authorization. - if (granted) { - qCDebug(lcMacSystray) << "Authorization for notifications has been granted, can display notifications."; - } else { - qCDebug(lcMacSystray) << "Authorization for notifications not granted."; - if(error) { - const auto errorDescription = QString::fromNSString(error.localizedDescription); - qCDebug(lcMacSystray) << "Error from notification center: " << errorDescription; - } + [center requestAuthorizationWithOptions:(authOptions) completionHandler:^(BOOL granted, NSError * _Nullable error) { + // Enable or disable features based on authorization. + if (granted) { + qCDebug(lcMacSystray) << "Authorization for notifications has been granted, can display notifications."; + } else { + qCDebug(lcMacSystray) << "Authorization for notifications not granted."; + if (error) { + const auto errorDescription = QString::fromNSString(error.localizedDescription); + qCDebug(lcMacSystray) << "Error from notification center: " << errorDescription; } + } }]; } @@ -198,8 +197,8 @@ void setUserNotificationCenterDelegate() static dispatch_once_t once; dispatch_once(&once, ^{ - id delegate = [[NotificationCenterDelegate alloc] init]; - [center setDelegate:delegate]; + id delegate = [[NotificationCenterDelegate alloc] init]; + [center setDelegate:delegate]; }); } @@ -260,7 +259,7 @@ void sendOsXTalkNotification(const QString &title, const QString &message, const content.categoryIdentifier = @"TALK_MESSAGE"; content.userInfo = [NSDictionary dictionaryWithObjects:@[accountNS, tokenNS, replyToNS] forKeys:@[@"account", @"token", @"replyTo"]]; - UNTimeIntervalNotificationTrigger * const trigger = [UNTimeIntervalNotificationTrigger triggerWithTimeInterval:1 repeats: NO]; + UNTimeIntervalNotificationTrigger * const trigger = [UNTimeIntervalNotificationTrigger triggerWithTimeInterval:1 repeats:NO]; UNNotificationRequest * const request = [UNNotificationRequest requestWithIdentifier:@"NCTalkMessageNotification" content:content trigger:trigger]; [center addNotificationRequest:request withCompletionHandler:nil]; From 53cc438bf1ecad4bd45b317c04313040783528bc Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Tue, 25 Jul 2023 07:13:32 +0800 Subject: [PATCH 5/5] Use QSharedPointer::create for talk reply in systray.mm Signed-off-by: Claudio Cambra --- src/gui/systray.mm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/gui/systray.mm b/src/gui/systray.mm index f17372baf7..505d18ec99 100644 --- a/src/gui/systray.mm +++ b/src/gui/systray.mm @@ -58,7 +58,8 @@ void sendTalkReply(UNNotificationResponse *response, UNNotificationContent* cont << "Token:" << qToken << "Account:" << qAccount; - const auto talkReply = QSharedPointer(new OCC::TalkReply(accountState.data(), OCC::Systray::instance())); + const auto talkReply = QSharedPointer::create( + accountState.data(), OCC::Systray::instance()); talkReply->sendReplyMessage(qToken, qReply, qReplyTo); }