SYNERGY-1032 - Add MacOS version check and disabl UserNotification library if needed (#7046)

* SYNERGY-1032 - Add MacOS version check and disabl UserNotification library if needed

* SYNERGY-1032 - Update changelog

* SYNERGY-1032 - Add debug message

* SYNERGY-1032 - Build for MacOS 10.15 on Azure

* SYNERGY-1032 - Build for MacOS 10.14 instead of 10.15
This commit is contained in:
Igor Sikachyna
2021-07-02 12:40:27 +03:00
committed by GitHub
parent 89363240eb
commit fdb947e0af
6 changed files with 80 additions and 56 deletions

View File

@ -162,12 +162,26 @@ if (UNIX)
if (APPLE)
set (CMAKE_CXX_FLAGS "--sysroot ${CMAKE_OSX_SYSROOT} ${CMAKE_CXX_FLAGS} -DGTEST_USE_OWN_TR1_TUPLE=1")
if(NOT CMAKE_OSX_DEPLOYMENT_TARGET)
set(CMAKE_OSX_DEPLOYMENT_TARGET 11.0)
endif()
if(CMAKE_OSX_DEPLOYMENT_TARGET GREATER_EQUAL 11.0)
set(SYNERGY_OSX_DEPLOYMENT_TARGET 1100)
elseif(CMAKE_OSX_DEPLOYMENT_TARGET GREATER_EQUAL 10.15)
set(SYNERGY_OSX_DEPLOYMENT_TARGET 1015)
elseif(CMAKE_OSX_DEPLOYMENT_TARGET GREATER_EQUAL 10.14)
set(SYNERGY_OSX_DEPLOYMENT_TARGET 1014)
else()
set(SYNERGY_OSX_DEPLOYMENT_TARGET 1013)
endif()
add_compile_definitions(OSX_DEPLOYMENT_TARGET=${SYNERGY_OSX_DEPLOYMENT_TARGET})
find_library (lib_ScreenSaver ScreenSaver)
find_library (lib_IOKit IOKit)
find_library (lib_ApplicationServices ApplicationServices)
find_library (lib_Foundation Foundation)
find_library (lib_Carbon Carbon)
find_library (lib_UserNotifications UserNotifications)
list (APPEND libs
${lib_ScreenSaver}
@ -175,9 +189,15 @@ if (UNIX)
${lib_ApplicationServices}
${lib_Foundation}
${lib_Carbon}
${lib_UserNotifications}
)
if(SYNERGY_OSX_DEPLOYMENT_TARGET GREATER_EQUAL 1014)
find_library (lib_UserNotifications UserNotifications)
list (APPEND libs
${lib_UserNotifications}
)
endif()
else() # not-apple
# add include dir for bsd (posix uses /usr/include/)

View File

@ -9,6 +9,7 @@ Bug fixes:
- #7029 | #7033 Wrong encoding for text copied between linux and windows
- #7015 Fix Windows service not starting up after sleep
- #7036 Fix tray icon not changing theme on Big Sur
- #7046 Fix MacOS 10.13 build
Enhancements:
- #6998 Remove functionality related to the screen saver synchronisation

View File

@ -80,13 +80,13 @@ jobs:
catalina-std:
image: macOS-10.15
platform: x86-64
version: 10.13
version: 10.14
buildType: "standard"
prefix: "synergy"
catalina-ent:
image: macOS-10.15
platform: x86-64
version: 10.13
version: 10.14
buildType: "enterprise"
prefix: "synergy-enterprise"
pool:

View File

@ -5,9 +5,12 @@ extern "C" {
#endif
#import <Cocoa/Cocoa.h>
#if OSX_DEPLOYMENT_TARGET >= 1014
#import <UserNotifications/UNUserNotificationCenter.h>
@interface AppDelegate : NSObject <NSApplicationDelegate, NSUserNotificationCenterDelegate, UNUserNotificationCenterDelegate>
#else
@interface AppDelegate : NSObject <NSApplicationDelegate, NSUserNotificationCenterDelegate>
#endif
@end

View File

@ -12,13 +12,16 @@
-(void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
[[NSUserNotificationCenter defaultUserNotificationCenter] setDelegate:self];
#if OSX_DEPLOYMENT_TARGET >= 1014
[[UNUserNotificationCenter currentNotificationCenter] setDelegate:self];
#endif
}
-(BOOL)userNotificationCenter:(NSUserNotificationCenter *)center shouldPresentNotification:(NSUserNotification *)notification{
return YES;
}
#if OSX_DEPLOYMENT_TARGET >= 1014
-(void)userNotificationCenter:(UNUserNotificationCenter *)center
willPresentNotification:(UNNotification *)notification
withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler{
@ -29,5 +32,6 @@
completionHandler(presentationOptions);
}
#endif
@end

View File

@ -29,23 +29,22 @@
void requestOSXNotificationPermission()
{
if (@available(macOS 10.14, *))
#if OSX_DEPLOYMENT_TARGET >= 1014
if (isOSXDevelopmentBuild())
{
if (isOSXDevelopmentBuild())
{
qWarning("Not requesting notification permission in dev build");
return;
}
UNUserNotificationCenter* center = [UNUserNotificationCenter currentNotificationCenter];
[center requestAuthorizationWithOptions:(UNAuthorizationOptionAlert + UNAuthorizationOptionSound)
completionHandler:^(BOOL granted, NSError * _Nullable error) {
if(error != nil)
{
qWarning("Notification permission request error: %s", [[NSString stringWithFormat:@"%@", error] UTF8String]);
}
}];
qWarning("Not requesting notification permission in dev build");
return;
}
UNUserNotificationCenter* center = [UNUserNotificationCenter currentNotificationCenter];
[center requestAuthorizationWithOptions:(UNAuthorizationOptionAlert + UNAuthorizationOptionSound)
completionHandler:^(BOOL granted, NSError * _Nullable error) {
if(error != nil)
{
qWarning("Notification permission request error: %s", [[NSString stringWithFormat:@"%@", error] UTF8String]);
}
}];
#endif
}
bool
@ -58,44 +57,41 @@ isOSXDevelopmentBuild()
bool
showOSXNotification(const QString& title, const QString& body)
{
if (@available(macOS 10.14, *))
#if OSX_DEPLOYMENT_TARGET >= 1014
// accessing notification center on unsigned build causes an immidiate
// application shutodown (in this case synergys) and cannot be caught
// to avoid issues with it need to first check if this is a dev build
if (isOSXDevelopmentBuild())
{
// accessing notification center on unsigned build causes an immidiate
// application shutodown (in this case synergys) and cannot be caught
// to avoid issues with it need to first check if this is a dev build
if (isOSXDevelopmentBuild())
{
qWarning("Not showing notification in dev build");
return false;
}
requestOSXNotificationPermission();
UNUserNotificationCenter* center = [UNUserNotificationCenter currentNotificationCenter];
UNMutableNotificationContent *content = [[UNMutableNotificationContent alloc] init];
content.title = title.toNSString();
content.body = body.toNSString();
// Create the request object.
UNNotificationRequest* request = [UNNotificationRequest
requestWithIdentifier:@"SecureInput" content:content trigger:nil];
[center addNotificationRequest:request withCompletionHandler:^(NSError * _Nullable error) {
if (error != nil) {
qWarning("Notification display request error: %s", [[NSString stringWithFormat:@"%@", error] UTF8String]);
}
}];
}
else
{
NSUserNotification* notification = [[NSUserNotification alloc] init];
notification.title = title.toNSString();
notification.informativeText = body.toNSString();
notification.soundName = NSUserNotificationDefaultSoundName; //Will play a default sound
[[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification: notification];
[notification autorelease];
qWarning("Not showing notification in dev build");
return false;
}
requestOSXNotificationPermission();
UNUserNotificationCenter* center = [UNUserNotificationCenter currentNotificationCenter];
UNMutableNotificationContent *content = [[UNMutableNotificationContent alloc] init];
content.title = title.toNSString();
content.body = body.toNSString();
// Create the request object.
UNNotificationRequest* request = [UNNotificationRequest
requestWithIdentifier:@"SecureInput" content:content trigger:nil];
[center addNotificationRequest:request withCompletionHandler:^(NSError * _Nullable error) {
if (error != nil) {
qWarning("Notification display request error: %s", [[NSString stringWithFormat:@"%@", error] UTF8String]);
}
}];
#else
NSUserNotification* notification = [[NSUserNotification alloc] init];
notification.title = title.toNSString();
notification.informativeText = body.toNSString();
notification.soundName = NSUserNotificationDefaultSoundName; //Will play a default sound
[[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification: notification];
[notification autorelease];
#endif
return true;
}