mirror of
https://github.com/nextcloud/desktop.git
synced 2025-10-26 11:17:43 +00:00
Explicitly ask user for notification authorisation on launch
Signed-off-by: Claudio Cambra <claudio.cambra@gmail.com>
This commit is contained in:
parent
c6dd7da9fd
commit
a2cc2ace4a
@ -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,
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user