Explicitly ask user for notification authorisation on launch
authorClaudio Cambra <claudio.cambra@gmail.com>
Tue, 17 May 2022 17:20:04 +0000 (19:20 +0200)
committerClaudio Cambra <claudio.cambra@gmail.com>
Thu, 19 May 2022 08:59:12 +0000 (10:59 +0200)
Signed-off-by: Claudio Cambra <claudio.cambra@gmail.com>
src/gui/systray.cpp
src/gui/systray.h
src/gui/systray.mm

index 4f312f5df51f9dc30f098bb654e90d618cd39b2b..db04b01a43ddaf1bc60c7fc7504e134053c4cc93 100644 (file)
@@ -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,
index f2c8ccd4eec9983e5d94a449d74fccb4406fc386..18f01cd937aea807d840bed4edf045efd7f76706 100644 (file)
@@ -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);
index 392f5fde6c13547db9bd69c1289f6b75abd19cfc..e62d7125804958590db0d3e061b4d029b79f1951 100644 (file)
@@ -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) {