From d3046793033c55ad334902ef4de0ce2e25cdcd72 Mon Sep 17 00:00:00 2001 From: Black Hat Date: Sun, 14 Jul 2019 14:41:00 +0800 Subject: [PATCH] Fix crash on macOS. --- src/trayicon.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/trayicon.cpp b/src/trayicon.cpp index 1c3b0d8cf..6a55a1a47 100644 --- a/src/trayicon.cpp +++ b/src/trayicon.cpp @@ -130,7 +130,24 @@ void TrayIcon::setNotificationCount(int count) { void TrayIcon::setIsOnline(bool online) { m_isOnline = online; +#if defined(Q_OS_MAC) + if (online) { + auto labelText = + m_notificationCount == 0 ? "" : QString::number(m_notificationCount); + if (labelText == QtMac::badgeLabelText()) + return; + + QtMac::setBadgeLabelText(labelText); + } else { + auto labelText = "x"; + + if (labelText == QtMac::badgeLabelText()) + return; + + QtMac::setBadgeLabelText(labelText); + } +#else if (!icon_ || online == icon_->isOnline) return; @@ -142,6 +159,7 @@ void TrayIcon::setIsOnline(bool online) { setIcon(QIcon(tmp)); icon_ = tmp; +#endif emit isOnlineChanged(); }