mirror of
https://github.com/nextcloud/desktop.git
synced 2024-10-23 12:55:44 +03:00
Create systray_mac_common file for common systray functions
Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
This commit is contained in:
parent
dd2ca78884
commit
2f6ae0c4dd
3 changed files with 61 additions and 35 deletions
|
@ -283,7 +283,7 @@ endif()
|
|||
|
||||
IF( APPLE )
|
||||
list(APPEND client_SRCS cocoainitializer_mac.mm)
|
||||
list(APPEND client_SRCS systray.mm)
|
||||
list(APPEND client_SRCS systray.mm systray_mac_common.mm)
|
||||
|
||||
if (BUILD_FILE_PROVIDER_MODULE)
|
||||
list(APPEND client_SRCS
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
#include "QtCore/qurl.h"
|
||||
#include <QLoggingCategory>
|
||||
#include <QString>
|
||||
#include <QUrl>
|
||||
|
||||
#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>
|
||||
|
@ -76,7 +76,7 @@ void sendTalkReply(UNNotificationResponse *response, UNNotificationContent* cont
|
|||
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);
|
||||
|
@ -111,20 +111,6 @@ didReceiveNotificationResponse:(UNNotificationResponse *)response
|
|||
|
||||
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()
|
||||
{
|
||||
|
@ -266,19 +252,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
|
||||
|
|
55
src/gui/systray_mac_common.mm
Normal file
55
src/gui/systray_mac_common.mm
Normal file
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
* Copyright (C) 2023 by Claudio Cambra <claudio.cambra@nextcloud.com>
|
||||
*
|
||||
* 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"];
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue