Skip to content
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

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

Merged
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 22 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -162,22 +162,42 @@ 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}
${lib_IOKit}
${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/)
Expand Down
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,13 @@ jobs:
catalina-std:
image: macOS-10.15
platform: x86-64
version: 10.13
version: 10.15
igor-sikachyna marked this conversation as resolved.
Show resolved Hide resolved
buildType: "standard"
prefix: "synergy"
catalina-ent:
image: macOS-10.15
platform: x86-64
version: 10.13
version: 10.15
buildType: "enterprise"
prefix: "synergy-enterprise"
pool:
Expand Down
5 changes: 4 additions & 1 deletion src/gui/src/AppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions src/gui/src/AppDelegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@ @implementation AppDelegate
-(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{
Expand All @@ -29,5 +32,6 @@ -(void)userNotificationCenter:(UNUserNotificationCenter *)center

completionHandler(presentationOptions);
}
#endif

@end
88 changes: 42 additions & 46 deletions src/gui/src/OSXHelpers.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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("Not requesting notification permission in dev build");
return;
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
Expand All @@ -58,44 +57,41 @@ void requestOSXNotificationPermission()
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;
}
qWarning("Not showing notification in dev build");
return false;
}

requestOSXNotificationPermission();
requestOSXNotificationPermission();

UNUserNotificationCenter* center = [UNUserNotificationCenter currentNotificationCenter];
UNUserNotificationCenter* center = [UNUserNotificationCenter currentNotificationCenter];

UNMutableNotificationContent *content = [[UNMutableNotificationContent alloc] init];
content.title = title.toNSString();
content.body = body.toNSString();
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];
// 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];
}
[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;
}

Expand Down