diff --git a/CMakeLists.txt b/CMakeLists.txt index 9edbd8ffa..f3463d861 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,9 +46,6 @@ find_package(Qt5 5.12 REQUIRED Widgets Network Quick Qml Gui Svg Multimedia) if(LINUX) find_package(Qt5DBus REQUIRED) endif(LINUX) -if (APPLE) - find_package(Qt5MacExtras REQUIRED) -endif(APPLE) # Qt5_Prefix is only used to show Qt path in message() # Qt5_BinDir is where all the binary tools for Qt are if (QT_QMAKE_EXECUTABLE) @@ -212,9 +209,7 @@ target_link_libraries(${PROJECT_NAME} target_compile_definitions(${PROJECT_NAME} PRIVATE GIT_SHA1="${GIT_SHA1}" LIB_GIT_SHA1="${LIB_GIT_SHA1}") -if (APPLE) - target_link_libraries(${PROJECT_NAME} Qt5::MacExtras) -elseif(LINUX) +if(LINUX) target_link_libraries(${PROJECT_NAME} Qt5::DBus) endif() diff --git a/src/notifications/managermac.mm b/src/notifications/managermac.mm index bcd8c776d..921bc8a23 100644 --- a/src/notifications/managermac.mm +++ b/src/notifications/managermac.mm @@ -1,13 +1,12 @@ #include "manager.h" -#include -#include +#import -@interface NSUserNotification (CFIPrivate) -- (void)set_identityImage:(NSImage*)image; -@end +#include -NotificationsManager::NotificationsManager(QObject* parent) : QObject(parent) {} +NotificationsManager::NotificationsManager(QObject* parent) : QObject(parent) { + +} void NotificationsManager::postNotification(const QString& roomId, const QString& eventId, @@ -19,16 +18,37 @@ void NotificationsManager::postNotification(const QString& roomId, Q_UNUSED(eventId); Q_UNUSED(icon); - NSUserNotification* notif = [[NSUserNotification alloc] init]; + UNUserNotificationCenter* center = + [UNUserNotificationCenter currentNotificationCenter]; + UNAuthorizationOptions options = UNAuthorizationOptionAlert + UNAuthorizationOptionSound; - notif.title = roomName.toNSString(); - notif.subtitle = QString("%1 sent a message").arg(senderName).toNSString(); - notif.informativeText = text.toNSString(); - notif.soundName = NSUserNotificationDefaultSoundName; + [center requestAuthorizationWithOptions:options + completionHandler:^(BOOL granted, NSError * _Nullable error) { + if (!granted) { + NSLog(@"Something went wrong"); + } + }]; - [[NSUserNotificationCenter defaultUserNotificationCenter] - deliverNotification:notif]; - [notif autorelease]; + UNTimeIntervalNotificationTrigger *trigger = [UNTimeIntervalNotificationTrigger triggerWithTimeInterval:300 + repeats:NO]; + + UNMutableNotificationContent *content = [UNMutableNotificationContent new]; + + content.title = roomName.toNSString(); + content.subtitle = QString("%1 sent a message").arg(senderName).toNSString(); + content.body = text.toNSString(); + content.sound = [UNNotificationSound defaultSound]; + + NSString *identifier = QApplication::applicationName().toNSString(); + + UNNotificationRequest *request = [UNNotificationRequest requestWithIdentifier:identifier + content:content trigger:trigger]; + + [center addNotificationRequest:request withCompletionHandler:^(NSError * _Nullable error) { + if (error != nil) { + NSLog(@"Something went wrong: %@",error); + } + }]; } // unused