Try to use UserNotifications.
This commit is contained in:
@@ -46,9 +46,6 @@ find_package(Qt5 5.12 REQUIRED Widgets Network Quick Qml Gui Svg Multimedia)
|
|||||||
if(LINUX)
|
if(LINUX)
|
||||||
find_package(Qt5DBus REQUIRED)
|
find_package(Qt5DBus REQUIRED)
|
||||||
endif(LINUX)
|
endif(LINUX)
|
||||||
if (APPLE)
|
|
||||||
find_package(Qt5MacExtras REQUIRED)
|
|
||||||
endif(APPLE)
|
|
||||||
# Qt5_Prefix is only used to show Qt path in message()
|
# Qt5_Prefix is only used to show Qt path in message()
|
||||||
# Qt5_BinDir is where all the binary tools for Qt are
|
# Qt5_BinDir is where all the binary tools for Qt are
|
||||||
if (QT_QMAKE_EXECUTABLE)
|
if (QT_QMAKE_EXECUTABLE)
|
||||||
@@ -212,9 +209,7 @@ target_link_libraries(${PROJECT_NAME}
|
|||||||
target_compile_definitions(${PROJECT_NAME} PRIVATE
|
target_compile_definitions(${PROJECT_NAME} PRIVATE
|
||||||
GIT_SHA1="${GIT_SHA1}" LIB_GIT_SHA1="${LIB_GIT_SHA1}")
|
GIT_SHA1="${GIT_SHA1}" LIB_GIT_SHA1="${LIB_GIT_SHA1}")
|
||||||
|
|
||||||
if (APPLE)
|
if(LINUX)
|
||||||
target_link_libraries(${PROJECT_NAME} Qt5::MacExtras)
|
|
||||||
elseif(LINUX)
|
|
||||||
target_link_libraries(${PROJECT_NAME} Qt5::DBus)
|
target_link_libraries(${PROJECT_NAME} Qt5::DBus)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
#include "manager.h"
|
#include "manager.h"
|
||||||
|
|
||||||
#include <Foundation/Foundation.h>
|
#import <UserNotifications/UserNotifications.h>
|
||||||
#include <QtMac>
|
|
||||||
|
|
||||||
@interface NSUserNotification (CFIPrivate)
|
#include <QApplication>
|
||||||
- (void)set_identityImage:(NSImage*)image;
|
|
||||||
@end
|
|
||||||
|
|
||||||
NotificationsManager::NotificationsManager(QObject* parent) : QObject(parent) {}
|
NotificationsManager::NotificationsManager(QObject* parent) : QObject(parent) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void NotificationsManager::postNotification(const QString& roomId,
|
void NotificationsManager::postNotification(const QString& roomId,
|
||||||
const QString& eventId,
|
const QString& eventId,
|
||||||
@@ -19,16 +18,37 @@ void NotificationsManager::postNotification(const QString& roomId,
|
|||||||
Q_UNUSED(eventId);
|
Q_UNUSED(eventId);
|
||||||
Q_UNUSED(icon);
|
Q_UNUSED(icon);
|
||||||
|
|
||||||
NSUserNotification* notif = [[NSUserNotification alloc] init];
|
UNUserNotificationCenter* center =
|
||||||
|
[UNUserNotificationCenter currentNotificationCenter];
|
||||||
|
UNAuthorizationOptions options = UNAuthorizationOptionAlert + UNAuthorizationOptionSound;
|
||||||
|
|
||||||
notif.title = roomName.toNSString();
|
[center requestAuthorizationWithOptions:options
|
||||||
notif.subtitle = QString("%1 sent a message").arg(senderName).toNSString();
|
completionHandler:^(BOOL granted, NSError * _Nullable error) {
|
||||||
notif.informativeText = text.toNSString();
|
if (!granted) {
|
||||||
notif.soundName = NSUserNotificationDefaultSoundName;
|
NSLog(@"Something went wrong");
|
||||||
|
}
|
||||||
|
}];
|
||||||
|
|
||||||
[[NSUserNotificationCenter defaultUserNotificationCenter]
|
UNTimeIntervalNotificationTrigger *trigger = [UNTimeIntervalNotificationTrigger triggerWithTimeInterval:300
|
||||||
deliverNotification:notif];
|
repeats:NO];
|
||||||
[notif autorelease];
|
|
||||||
|
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
|
// unused
|
||||||
|
|||||||
Reference in New Issue
Block a user