Skip to content

Commit

Permalink
FIX(client): Experimental notifications on OSX
Browse files Browse the repository at this point in the history
  • Loading branch information
Hartmnt committed Jun 23, 2024
1 parent a1e8ad1 commit c276163
Showing 1 changed file with 18 additions and 29 deletions.
47 changes: 18 additions & 29 deletions src/mumble/Log_macx.mm
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include <Foundation/Foundation.h>

#include "widgets/TrayIcon.h"
#include "Global.h"

#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1080
Expand Down Expand Up @@ -72,34 +73,22 @@ static bool growl_available() {
#endif // QT_VERSION

void Log::postNotification(MsgType mt, const QString &plain) {
QString title = msgName(mt);
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1080
# if QT_VERSION >= QT_VERSION_CHECK(5, 9, 0)
const QOperatingSystemVersion current = QOperatingSystemVersion::current();
if (current.majorVersion() > 10 || (current.majorVersion() == 10 && current.minorVersion() >= 8)) {
# else
if (QSysInfo::MacintoshVersion >= QSysInfo::MV_MOUNTAINLION) {
# endif
NSUserNotificationCenter *userNotificationCenter = [NSUserNotificationCenter defaultUserNotificationCenter];
if (userNotificationCenter.delegate == nil) {
// We hand the delegate property a delegate with a retain count of 1. We don't keep
// a reference to the delegate anywhere else, so it's not really a leak.
userNotificationCenter.delegate = [[MUUserNotificationCenterDelegate alloc] init];
}
NSUserNotification *userNotification = [[[NSUserNotification alloc] init] autorelease];
userNotification.title = [Log_QString_to_NSString(title) autorelease];
userNotification.informativeText = [Log_QString_to_NSString(plain) autorelease];
[userNotificationCenter scheduleNotification:userNotification];
} else
#endif
{
#if QT_VERSION < 0x050800
QString qsScript = QString::fromLatin1(
"tell application \"GrowlHelperApp\"\n"
" notify with name \"%1\" title \"%1\" description \"%2\" application name \"Mumble\"\n"
"end tell\n").arg(title).arg(plain);
if (growl_available())
qt_mac_execute_apple_script(qsScript, nullptr);
#endif
QSystemTrayIcon::MessageIcon msgIcon;
switch (mt) {
case DebugInfo:
case CriticalError:
msgIcon = QSystemTrayIcon::Critical;
break;
case Warning:
msgIcon = QSystemTrayIcon::Warning;
break;
case TextMessage:
case PrivateTextMessage:
msgIcon = QSystemTrayIcon::NoIcon;
break;
default:
msgIcon = QSystemTrayIcon::Information;
break;
}
Global::get().trayIcon->showMessage(msgName(mt), plain, msgIcon);
}

0 comments on commit c276163

Please sign in to comment.