From a2cc2ace4a3f7f71e43eaa35dbd4b0071be778a5 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Tue, 17 May 2022 19:20:04 +0200 Subject: [PATCH] Explicitly ask user for notification authorisation on launch Signed-off-by: Claudio Cambra --- src/gui/systray.cpp | 2 +- src/gui/systray.h | 7 ++++++- src/gui/systray.mm | 15 +++++++++++++-- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/gui/systray.cpp b/src/gui/systray.cpp index 4f312f5df..db04b01a4 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 f2c8ccd4e..18f01cd93 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 392f5fde6..e62d71258 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) { -- 2.30.2