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
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 80 additions and 56 deletions

View file

@ -162,12 +162,26 @@ if (UNIX)
if (APPLE) if (APPLE)
set (CMAKE_CXX_FLAGS "--sysroot ${CMAKE_OSX_SYSROOT} ${CMAKE_CXX_FLAGS} -DGTEST_USE_OWN_TR1_TUPLE=1") 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_ScreenSaver ScreenSaver)
find_library (lib_IOKit IOKit) find_library (lib_IOKit IOKit)
find_library (lib_ApplicationServices ApplicationServices) find_library (lib_ApplicationServices ApplicationServices)
find_library (lib_Foundation Foundation) find_library (lib_Foundation Foundation)
find_library (lib_Carbon Carbon) find_library (lib_Carbon Carbon)
find_library (lib_UserNotifications UserNotifications)
list (APPEND libs list (APPEND libs
${lib_ScreenSaver} ${lib_ScreenSaver}
@ -175,9 +189,15 @@ if (UNIX)
${lib_ApplicationServices} ${lib_ApplicationServices}
${lib_Foundation} ${lib_Foundation}
${lib_Carbon} ${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 else() # not-apple
# add include dir for bsd (posix uses /usr/include/) # 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 - #7029 | #7033 Wrong encoding for text copied between linux and windows
- #7015 Fix Windows service not starting up after sleep - #7015 Fix Windows service not starting up after sleep
- #7036 Fix tray icon not changing theme on Big Sur - #7036 Fix tray icon not changing theme on Big Sur
- #7046 Fix MacOS 10.13 build
Enhancements: Enhancements:
- #6998 Remove functionality related to the screen saver synchronisation - #6998 Remove functionality related to the screen saver synchronisation

View file

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

View file

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

View file

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

View file

@ -29,23 +29,22 @@
void requestOSXNotificationPermission() 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;
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]);
}
}];
} }
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 bool
@ -58,44 +57,41 @@ isOSXDevelopmentBuild()
bool bool
showOSXNotification(const QString& title, const QString& body) 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 qWarning("Not showing notification in dev build");
// application shutodown (in this case synergys) and cannot be caught return false;
// 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];
} }
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; return true;
} }