Skip to content

Commit

Permalink
Refactoring with QString::toNSString
Browse files Browse the repository at this point in the history
The behavior of MacNotificationHandler::showNotification() has not been
changed.
  • Loading branch information
hebasto authored and furszy committed Mar 11, 2021
1 parent 69b3330 commit 8762e81
Showing 1 changed file with 4 additions and 19 deletions.
23 changes: 4 additions & 19 deletions src/qt/macnotificationhandler.mm
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,10 @@ - (NSString *)__bundleIdentifier
{
// check if users OS has support for NSUserNotification
if(this->hasUserNotificationCenterSupport()) {
// okay, seems like 10.8+
QByteArray utf8 = title.toUtf8();
char* cString = (char *)utf8.constData();
NSString *titleMac = [[NSString alloc] initWithUTF8String:cString];

utf8 = text.toUtf8();
cString = (char *)utf8.constData();
NSString *textMac = [[NSString alloc] initWithUTF8String:cString];

// do everything weak linked (because we will keep <10.8 compatibility)
id userNotification = [[NSClassFromString(@"NSUserNotification") alloc] init];
[userNotification performSelector:@selector(setTitle:) withObject:titleMac];
[userNotification performSelector:@selector(setInformativeText:) withObject:textMac];

id notificationCenterInstance = [NSClassFromString(@"NSUserNotificationCenter") performSelector:@selector(defaultUserNotificationCenter)];
[notificationCenterInstance performSelector:@selector(deliverNotification:) withObject:userNotification];

[titleMac release];
[textMac release];
NSUserNotification* userNotification = [[NSUserNotification alloc] init];
userNotification.title = title.toNSString();
userNotification.informativeText = text.toNSString();
[[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification: userNotification];
[userNotification release];
}
}
Expand Down

0 comments on commit 8762e81

Please sign in to comment.