Bitcoin ABC 0.30.7
P2P Digital Currency
macnotificationhandler.mm
Go to the documentation of this file.
1// Copyright (c) 2011-2013 The Bitcoin Core developers
2// Distributed under the MIT software license, see the accompanying
3// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
6
7#undef slots
8#include <Cocoa/Cocoa.h>
9#import <objc/runtime.h>
10
11// Add an obj-c category (extension) to return the expected bundle identifier
13- (NSString *)__bundleIdentifier {
14 if (self == [NSBundle mainBundle]) {
15 return @"org.bitcoinabc.BitcoinABC-Qt";
16 } else {
17 return [self __bundleIdentifier];
18 }
19}
20@end
21
23 const QString &text) {
24 // check if users OS has support for NSUserNotification
25 if (this->hasUserNotificationCenterSupport()) {
26 NSUserNotification *userNotification =
27 [[NSUserNotification alloc] init];
28 userNotification.title = title.toNSString();
29 userNotification.informativeText = text.toNSString();
30 [[NSUserNotificationCenter defaultUserNotificationCenter]
31 deliverNotification:userNotification];
32 [userNotification release];
33 }
34}
35
37 Class possibleClass = NSClassFromString(@"NSUserNotificationCenter");
38
39 // check if users OS has support for NSUserNotification
40 if (possibleClass != nil) {
41 return true;
42 }
43 return false;
44}
45
47 static MacNotificationHandler *s_instance = nullptr;
48 if (!s_instance) {
50
51 Class aPossibleClass = objc_getClass("NSBundle");
52 if (aPossibleClass) {
53 // change NSBundle -bundleIdentifier method to return a correct
54 // bundle identifier a bundle identifier is required to use OSXs
55 // User Notification Center
56 method_exchangeImplementations(
57 class_getInstanceMethod(aPossibleClass,
58 @selector(bundleIdentifier)),
59 class_getInstanceMethod(aPossibleClass,
60 @selector(__bundleIdentifier)));
61 }
62 }
63 return s_instance;
64}
Macintosh-specific notification handler (supports UserNotificationCenter).
bool hasUserNotificationCenterSupport()
check if OS can handle UserNotifications
static MacNotificationHandler * instance()
void showNotification(const QString &title, const QString &text)
shows a macOS 10.8+ UserNotification in the UserNotificationCenter
static MacDockIconHandler * s_instance