diff --git a/src/gui/systray.cpp b/src/gui/systray.cpp index 4f312f5df5..db04b01a43 100644 --- a/src/gui/systray.cpp +++ b/src/gui/systray.cpp @@ -101,7 +101,7 @@ Systray::Systray() #ifdef Q_OS_MACOS setUserNotificationCenterDelegate(); - checkNotificationAuth(); + checkNotificationAuth(MacNotificationAuthorizationOptions::Default); // No provisional auth, ask user explicitly first time registerNotificationCategories(QString(tr("Download"))); #else connect(AccountManager::instance(), &AccountManager::accountAdded, diff --git a/src/gui/systray.h b/src/gui/systray.h index f2c8ccd4ee..18f01cd937 100644 --- a/src/gui/systray.h +++ b/src/gui/systray.h @@ -40,8 +40,13 @@ public: }; #ifdef Q_OS_MACOS +enum MacNotificationAuthorizationOptions { + Default = 0, + Provisional +}; + void setUserNotificationCenterDelegate(); -void checkNotificationAuth(); +void checkNotificationAuth(MacNotificationAuthorizationOptions authOptions = MacNotificationAuthorizationOptions::Provisional); void registerNotificationCategories(const QString &localizedDownloadString); bool canOsXSendUserNotification(); void sendOsXUserNotification(const QString &title, const QString &message); diff --git a/src/gui/systray.mm b/src/gui/systray.mm index 392f5fde6c..e62d712580 100644 --- a/src/gui/systray.mm +++ b/src/gui/systray.mm @@ -43,6 +43,11 @@ Q_LOGGING_CATEGORY(lcMacSystray, "nextcloud.gui.macsystray") namespace OCC { +enum MacNotificationAuthorizationOptions { + Default = 0, + Provisional +}; + double statusBarThickness() { return [NSStatusBar systemStatusBar].thickness; @@ -78,10 +83,16 @@ void registerNotificationCategories(const QString &localisedDownloadString) { [[UNUserNotificationCenter currentNotificationCenter] setNotificationCategories:[NSSet setWithObjects:generalCategory, updateCategory, nil]]; } -void checkNotificationAuth() +void checkNotificationAuth(MacNotificationAuthorizationOptions additionalAuthOption = MacNotificationAuthorizationOptions::Provisional) { UNUserNotificationCenter* center = [UNUserNotificationCenter currentNotificationCenter]; - [center requestAuthorizationWithOptions:(UNAuthorizationOptionAlert + UNAuthorizationOptionSound + UNAuthorizationOptionProvisional) + UNAuthorizationOptions authOptions = UNAuthorizationOptionAlert + UNAuthorizationOptionSound; + + if(additionalAuthOption == MacNotificationAuthorizationOptions::Provisional) { + authOptions += UNAuthorizationOptionProvisional; + } + + [center requestAuthorizationWithOptions:(authOptions) completionHandler:^(BOOL granted, NSError * _Nullable error) { // Enable or disable features based on authorization. if(granted) {