-
Notifications
You must be signed in to change notification settings - Fork 807
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Backport/6498/stable 3.12 #6534
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a50eefb
Change minimun mac OS version to 10.13.
a49dfd8
Create systray_mac_common file for common systray functions
claucambra 951cd6a
macosx: Selectively compile UserNotifications component of systray de…
claucambra b59f81e
Do not try to link UserNotifications framework when building below 10.14
claucambra b50e1e3
Only set BUILD_FILE_PROVIDER_MODULE if deployment target high enough
claucambra 11612ca
Remove unneeded fallback for undefined cmake_osx_deployment_target
claucambra cd64e71
Set min OSX version via cmake.
camilasan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Copyright (C) 2023 by Claudio Cambra <[email protected]> | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, but | ||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY | ||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
* for more details. | ||
*/ | ||
|
||
#include <QWindow> | ||
|
||
#import <Cocoa/Cocoa.h> | ||
|
||
#include "systray.h" | ||
|
||
Q_LOGGING_CATEGORY(lcMacSystrayCommon, "nextcloud.gui.macsystraycommon") | ||
|
||
namespace OCC { | ||
|
||
double menuBarThickness() | ||
{ | ||
NSMenu * const mainMenu = [[NSApplication sharedApplication] mainMenu]; | ||
|
||
if (mainMenu == nil) { | ||
// Return this educated guess if something goes wrong. | ||
// As of macOS 12.4 this will always return 22, even on notched Macbooks. | ||
qCWarning(lcMacSystrayCommon) << "Got nil for main menu. " | ||
<< "Going with reasonable menu bar height guess."; | ||
return NSStatusBar.systemStatusBar.thickness; | ||
} | ||
|
||
return mainMenu.menuBarHeight; | ||
} | ||
|
||
void setTrayWindowLevelAndVisibleOnAllSpaces(QWindow *const window) | ||
{ | ||
NSView * const nativeView = (NSView *)window->winId(); | ||
NSWindow * const nativeWindow = (NSWindow *)(nativeView.window); | ||
[nativeWindow setCollectionBehavior:NSWindowCollectionBehaviorCanJoinAllSpaces | NSWindowCollectionBehaviorIgnoresCycle | | ||
NSWindowCollectionBehaviorTransient]; | ||
[nativeWindow setLevel:NSMainMenuWindowLevel]; | ||
} | ||
|
||
bool osXInDarkMode() | ||
{ | ||
NSString * const osxMode = [NSUserDefaults.standardUserDefaults stringForKey:@"AppleInterfaceStyle"]; | ||
return [osxMode containsString:@"Dark"]; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,32 @@ | ||
#include "QtCore/qurl.h" | ||
/* | ||
* Copyright (C) 2023 by Claudio Cambra <[email protected]> | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, but | ||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY | ||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
* for more details. | ||
*/ | ||
|
||
#include <QLoggingCategory> | ||
#include <QString> | ||
#include <QUrl> | ||
|
||
#import <Cocoa/Cocoa.h> | ||
#import <UserNotifications/UserNotifications.h> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
#include "account.h" | ||
#include "accountstate.h" | ||
#include "accountmanager.h" | ||
#include "config.h" | ||
#include "systray.h" | ||
#include "tray/talkreply.h" | ||
#include <QString> | ||
#include <QWindow> | ||
#include <QLoggingCategory> | ||
|
||
#import <Cocoa/Cocoa.h> | ||
#import <UserNotifications/UserNotifications.h> | ||
|
||
Q_LOGGING_CATEGORY(lcMacSystray, "nextcloud.gui.macsystray") | ||
Q_LOGGING_CATEGORY(lcMacSystrayUserNotifications, "nextcloud.gui.macsystrayusernotifications") | ||
|
||
/************************* Private utility functions *************************/ | ||
|
||
|
@@ -21,16 +35,16 @@ | |
void sendTalkReply(UNNotificationResponse *response, UNNotificationContent* content) | ||
{ | ||
if (!response || !content) { | ||
qCWarning(lcMacSystray()) << "Invalid notification response or content." | ||
<< "Can't send talk reply."; | ||
qCWarning(lcMacSystrayUserNotifications) << "Invalid notification response or content." | ||
<< "Can't send talk reply."; | ||
return; | ||
} | ||
|
||
UNTextInputNotificationResponse * const textInputResponse = (UNTextInputNotificationResponse*)response; | ||
|
||
if (!textInputResponse) { | ||
qCWarning(lcMacSystray()) << "Notification response was not a text input response." | ||
<< "Can't send talk reply."; | ||
qCWarning(lcMacSystrayUserNotifications) << "Notification response was not a text input response." | ||
<< "Can't send talk reply."; | ||
return; | ||
} | ||
|
||
|
@@ -47,16 +61,16 @@ void sendTalkReply(UNNotificationResponse *response, UNNotificationContent* cont | |
const auto accountState = OCC::AccountManager::instance()->accountFromUserId(qAccount); | ||
|
||
if (!accountState) { | ||
qCWarning(lcMacSystray()) << "Could not find account matching" << qAccount | ||
<< "Can't send talk reply."; | ||
qCWarning(lcMacSystrayUserNotifications) << "Could not find account matching" << qAccount | ||
<< "Can't send talk reply."; | ||
return; | ||
} | ||
|
||
qCDebug(lcMacSystray()) << "Sending talk reply from macOS notification." | ||
<< "Reply is:" << qReply | ||
<< "Replying to:" << qReplyTo | ||
<< "Token:" << qToken | ||
<< "Account:" << qAccount; | ||
qCDebug(lcMacSystrayUserNotifications) << "Sending talk reply from macOS notification." | ||
<< "Reply is:" << qReply | ||
<< "Replying to:" << qReplyTo | ||
<< "Token:" << qToken | ||
<< "Account:" << qAccount; | ||
|
||
// OCC::TalkReply deletes itself once it's done, fire and forget | ||
const auto talkReply = new OCC::TalkReply(accountState.data(), OCC::Systray::instance()); | ||
|
@@ -76,7 +90,7 @@ - (void)userNotificationCenter:(UNUserNotificationCenter *)center | |
willPresentNotification:(UNNotification *)notification | ||
withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler | ||
{ | ||
#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 110000 | ||
#if __MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_11_0 | ||
completionHandler(UNNotificationPresentationOptionSound + UNNotificationPresentationOptionBanner); | ||
#else | ||
completionHandler(UNNotificationPresentationOptionSound + UNNotificationPresentationOptionAlert); | ||
|
@@ -87,13 +101,16 @@ - (void)userNotificationCenter:(UNUserNotificationCenter *)center | |
didReceiveNotificationResponse:(UNNotificationResponse *)response | ||
withCompletionHandler:(void (^)(void))completionHandler | ||
{ | ||
qCDebug(lcMacSystray()) << "Received notification with category identifier:" << response.notification.request.content.categoryIdentifier | ||
<< "and action identifier" << response.actionIdentifier; | ||
qCDebug(lcMacSystrayUserNotifications) << "Received notification with category identifier:" | ||
<< response.notification.request.content.categoryIdentifier | ||
<< "and action identifier" | ||
<< response.actionIdentifier; | ||
|
||
UNNotificationContent * const content = response.notification.request.content; | ||
if ([content.categoryIdentifier isEqualToString:@"UPDATE"]) { | ||
|
||
if ([response.actionIdentifier isEqualToString:@"DOWNLOAD_ACTION"] || [response.actionIdentifier isEqualToString:UNNotificationDefaultActionIdentifier]) { | ||
qCDebug(lcMacSystray()) << "Opening update download url in browser."; | ||
qCDebug(lcMacSystrayUserNotifications) << "Opening update download url in browser."; | ||
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:[content.userInfo objectForKey:@"webUrl"]]]; | ||
} | ||
} else if ([content.categoryIdentifier isEqualToString:@"TALK_MESSAGE"]) { | ||
|
@@ -111,20 +128,6 @@ - (void)userNotificationCenter:(UNUserNotificationCenter *)center | |
|
||
namespace OCC { | ||
|
||
double menuBarThickness() | ||
{ | ||
NSMenu * const mainMenu = [[NSApplication sharedApplication] mainMenu]; | ||
|
||
if (mainMenu == nil) { | ||
// Return this educated guess if something goes wrong. | ||
// As of macOS 12.4 this will always return 22, even on notched Macbooks. | ||
qCWarning(lcMacSystray) << "Got nil for main menu. Going with reasonable menu bar height guess."; | ||
return NSStatusBar.systemStatusBar.thickness; | ||
} | ||
|
||
return mainMenu.menuBarHeight; | ||
} | ||
|
||
// TODO: Get this to actually check for permissions | ||
bool canOsXSendUserNotification() | ||
{ | ||
|
@@ -181,12 +184,12 @@ void checkNotificationAuth(MacNotificationAuthorizationOptions additionalAuthOpt | |
[center requestAuthorizationWithOptions:(authOptions) completionHandler:^(BOOL granted, NSError * _Nullable error) { | ||
// Enable or disable features based on authorization. | ||
if (granted) { | ||
qCDebug(lcMacSystray) << "Authorization for notifications has been granted, can display notifications."; | ||
qCDebug(lcMacSystrayUserNotifications) << "Authorization for notifications has been granted, can display notifications."; | ||
} else { | ||
qCDebug(lcMacSystray) << "Authorization for notifications not granted."; | ||
qCDebug(lcMacSystrayUserNotifications) << "Authorization for notifications not granted."; | ||
if (error) { | ||
const auto errorDescription = QString::fromNSString(error.localizedDescription); | ||
qCDebug(lcMacSystray) << "Error from notification center: " << errorDescription; | ||
qCDebug(lcMacSystrayUserNotifications) << "Error from notification center: " << errorDescription; | ||
} | ||
} | ||
}]; | ||
|
@@ -266,19 +269,4 @@ void sendOsXTalkNotification(const QString &title, const QString &message, const | |
[center addNotificationRequest:request withCompletionHandler:nil]; | ||
} | ||
|
||
void setTrayWindowLevelAndVisibleOnAllSpaces(QWindow *window) | ||
{ | ||
NSView * const nativeView = (NSView *)window->winId(); | ||
NSWindow * const nativeWindow = (NSWindow *)(nativeView.window); | ||
[nativeWindow setCollectionBehavior:NSWindowCollectionBehaviorCanJoinAllSpaces | NSWindowCollectionBehaviorIgnoresCycle | | ||
NSWindowCollectionBehaviorTransient]; | ||
[nativeWindow setLevel:NSMainMenuWindowLevel]; | ||
} | ||
|
||
bool osXInDarkMode() | ||
{ | ||
NSString * const osxMode = [NSUserDefaults.standardUserDefaults stringForKey:@"AppleInterfaceStyle"]; | ||
return [osxMode containsString:@"Dark"]; | ||
} | ||
|
||
} // OCC namespace |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cocoa/Cocoa.h
file not found