From: Claudio Cambra Date: Tue, 17 May 2022 17:20:04 +0000 (+0200) Subject: Explicitly ask user for notification authorisation on launch X-Git-Tag: archive/raspbian/3.16.7-1_deb13u1+rpi1~1^2~12^2~15^2~199^2 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=a2cc2ace4a3f7f71e43eaa35dbd4b0071be778a5;p=nextcloud-desktop.git Explicitly ask user for notification authorisation on launch Signed-off-by: Claudio Cambra --- 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) {