Browse Source

Merge pull request #7281 from vit9696/notifications2

Fix notification display on macOS
adaptive-webui-19844
sledgehammer999 7 years ago committed by GitHub
parent
commit
4f0d9605fe
  1. 1
      src/gui/macutilities.h
  2. 12
      src/gui/macutilities.mm
  3. 4
      src/gui/mainwindow.cpp

1
src/gui/macutilities.h

@ -35,5 +35,6 @@
QPixmap pixmapForExtension(const QString &ext, const QSize &size); QPixmap pixmapForExtension(const QString &ext, const QSize &size);
void overrideDockClickHandler(bool (*dockClickHandler)(id, SEL, ...)); void overrideDockClickHandler(bool (*dockClickHandler)(id, SEL, ...));
void displayNotification(const QString &title, const QString &message);
#endif // MACUTILITIES_H #endif // MACUTILITIES_H

12
src/gui/macutilities.mm

@ -69,3 +69,15 @@ void overrideDockClickHandler(bool (*dockClickHandler)(id, SEL, ...))
qWarning("Failed to register dock click handler"); qWarning("Failed to register dock click handler");
} }
} }
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];
}
}

4
src/gui/mainwindow.cpp

@ -1553,7 +1553,9 @@ void MainWindow::showNotificationBaloon(QString title, QString msg) const
reply.waitForFinished(); reply.waitForFinished();
if (!reply.isError()) if (!reply.isError())
return; return;
#elif (!defined(Q_OS_MAC)) #elif defined(Q_OS_MAC)
displayNotification(title, msg);
#else
if (m_systrayIcon && QSystemTrayIcon::supportsMessages()) if (m_systrayIcon && QSystemTrayIcon::supportsMessages())
m_systrayIcon->showMessage(title, msg, QSystemTrayIcon::Information, TIME_TRAY_BALLOON); m_systrayIcon->showMessage(title, msg, QSystemTrayIcon::Information, TIME_TRAY_BALLOON);
#endif #endif

Loading…
Cancel
Save