Skip to content

Commit

Permalink
Modernise property accessing in systray.mm
Browse files Browse the repository at this point in the history
Signed-off-by: Claudio Cambra <[email protected]>
  • Loading branch information
claucambra committed Apr 13, 2023
1 parent a08e00c commit 5cbf330
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions src/gui/systray.mm
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ - (void)userNotificationCenter:(UNUserNotificationCenter *)center
// 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;
Expand All @@ -127,7 +127,7 @@ - (void)userNotificationCenter:(UNUserNotificationCenter *)center
// TODO: Get this to actually check for permissions
bool canOsXSendUserNotification()
{
UNUserNotificationCenter * const center = [UNUserNotificationCenter currentNotificationCenter];
UNUserNotificationCenter * const center = UNUserNotificationCenter.currentNotificationCenter;
return center != nil;
}

Expand Down Expand Up @@ -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) {
Expand All @@ -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, ^{
Expand All @@ -215,36 +215,36 @@ void setUserNotificationCenterDelegate()

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];
}

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];
}

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()) {
Expand All @@ -269,15 +269,15 @@ 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];
}

bool osXInDarkMode()
{
NSString * const osxMode = [[NSUserDefaults standardUserDefaults] stringForKey:@"AppleInterfaceStyle"];
NSString * const osxMode = [NSUserDefaults.standardUserDefaults stringForKey:@"AppleInterfaceStyle"];
return [osxMode containsString:@"Dark"];
}

Expand Down

0 comments on commit 5cbf330

Please sign in to comment.