mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-08-20 13:23:34 -07:00
migrateAwayFromDeprecatedNSUserNotification
migrateAwayFromDeprecatedNSUserNotification migrateAwayFromDeprecatedNSUserNotification migrateAwayFromDeprecatedNSUserNotification migrateAwayFromDeprecatedNSUserNotification migrateAwayFromDeprecatedNSUserNotification migrateAwayFromDeprecatedNSUserNotification migrateAwayFromDeprecatedNSUserNotification migrateAwayFromDeprecatedNSUserNotification migrateAwayFromDeprecatedNSUserNotification migrateAwayFromDeprecatedNSUserNotification migrateAwayFromDeprecatedNSUserNotification migrateAwayFromDeprecatedNSUserNotification migrateAwayFromDeprecatedNSUserNotification
This commit is contained in:
parent
03efbac581
commit
6e60669214
4 changed files with 36 additions and 7 deletions
|
@ -296,7 +296,10 @@ if (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
|
|||
programupdater.h
|
||||
programupdater.cpp
|
||||
)
|
||||
target_link_libraries(qbt_gui PRIVATE objc)
|
||||
target_link_libraries(qbt_gui PRIVATE
|
||||
objc
|
||||
"-framework UserNotifications"
|
||||
)
|
||||
endif()
|
||||
|
||||
if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
|
||||
|
|
|
@ -80,6 +80,7 @@ DesktopIntegration::DesktopIntegration(QObject *parent)
|
|||
{
|
||||
#ifdef Q_OS_MACOS
|
||||
desktopIntegrationInstance = this;
|
||||
MacUtils::askForNotificationPermission();
|
||||
MacUtils::overrideDockClickHandler(handleDockClicked);
|
||||
m_menu->setAsDockMenu();
|
||||
#else
|
||||
|
|
|
@ -40,6 +40,7 @@ namespace MacUtils
|
|||
{
|
||||
QPixmap pixmapForExtension(const QString &ext, const QSize &size);
|
||||
void overrideDockClickHandler(bool (*dockClickHandler)(id, SEL, ...));
|
||||
void askForNotificationPermission();
|
||||
void displayNotification(const QString &title, const QString &message);
|
||||
void openFiles(const PathList &pathList);
|
||||
|
||||
|
|
|
@ -29,13 +29,17 @@
|
|||
#include "macutilities.h"
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <UniformTypeIdentifiers/UniformTypeIdentifiers.h>
|
||||
#import <UserNotifications/UserNotifications.h>
|
||||
#include <objc/message.h>
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QPixmap>
|
||||
#include <QSize>
|
||||
#include <QString>
|
||||
|
||||
#include "base/logger.h"
|
||||
#include "base/path.h"
|
||||
|
||||
QImage qt_mac_toQImage(CGImageRef image);
|
||||
|
@ -85,16 +89,36 @@ namespace MacUtils
|
|||
}
|
||||
}
|
||||
|
||||
void askForNotificationPermission()
|
||||
{
|
||||
@autoreleasepool
|
||||
{
|
||||
[UNUserNotificationCenter.currentNotificationCenter requestAuthorizationWithOptions:
|
||||
(UNAuthorizationOptionAlert + UNAuthorizationOptionSound)
|
||||
completionHandler:^([[maybe_unused]] BOOL granted, NSError * _Nullable error)
|
||||
{
|
||||
if (error)
|
||||
{
|
||||
LogMsg(QCoreApplication::translate("MacUtils", "Permission for notifications not granted. Error: \"%1\"").arg
|
||||
(QString::fromNSString(error.localizedDescription)), Log::WARNING);
|
||||
}
|
||||
}];
|
||||
}
|
||||
}
|
||||
|
||||
void displayNotification(const QString &title, const QString &message)
|
||||
{
|
||||
@autoreleasepool
|
||||
{
|
||||
NSUserNotification *notification = [[NSUserNotification alloc] init];
|
||||
notification.title = title.toNSString();
|
||||
notification.informativeText = message.toNSString();
|
||||
notification.soundName = NSUserNotificationDefaultSoundName;
|
||||
|
||||
[[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:notification];
|
||||
UNMutableNotificationContent *content = [[UNMutableNotificationContent alloc] init];
|
||||
content.title = title.toNSString();
|
||||
content.body = message.toNSString();
|
||||
content.sound = [UNNotificationSound defaultSound];
|
||||
UNNotificationRequest *request = [UNNotificationRequest requestWithIdentifier:
|
||||
[[NSUUID UUID] UUIDString] content:content
|
||||
trigger:nil];
|
||||
[UNUserNotificationCenter.currentNotificationCenter
|
||||
addNotificationRequest:request withCompletionHandler:nil];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue