diff --git a/src/ui/form/tray/trayicon.cpp b/src/ui/form/tray/trayicon.cpp index b8d2772f7..3cfa51c6c 100644 --- a/src/ui/form/tray/trayicon.cpp +++ b/src/ui/form/tray/trayicon.cpp @@ -541,19 +541,13 @@ void TrayIcon::sendAlertMessage() void TrayIcon::updateAlertTimer() { - if (!iniUser()->trayAnimateAlert()) + if (!iniUser()->trayAnimateAlert()) { + removeAlertTimer(); return; - - if (!m_alertTimer) { - m_alertTimer = new QTimer(this); - m_alertTimer->setInterval(1000); - - connect(m_alertTimer, &QTimer::timeout, this, [&] { - m_animatedAlert = !m_animatedAlert; - updateTrayIconShape(); - }); } + setupAlertTimer(); + m_animatedAlert = m_alerted; if (m_alerted) { @@ -563,6 +557,29 @@ void TrayIcon::updateAlertTimer() } } +void TrayIcon::setupAlertTimer() +{ + if (m_alertTimer) + return; + + m_alertTimer = new QTimer(this); + m_alertTimer->setInterval(1000); + + connect(m_alertTimer, &QTimer::timeout, this, [&] { + m_animatedAlert = !m_animatedAlert; + updateTrayIconShape(); + }); +} + +void TrayIcon::removeAlertTimer() +{ + if (!m_alertTimer) + return; + + delete m_alertTimer; + m_alertTimer = nullptr; +} + void TrayIcon::updateTrayIconShape() { QString mainIconPath; diff --git a/src/ui/form/tray/trayicon.h b/src/ui/form/tray/trayicon.h index 51f74b0bd..18227498b 100644 --- a/src/ui/form/tray/trayicon.h +++ b/src/ui/form/tray/trayicon.h @@ -105,6 +105,10 @@ protected slots: void sendAlertMessage(); void updateAlertTimer(); + + void setupAlertTimer(); + void removeAlertTimer(); + void updateTrayIconShape(); void addHotKey(QAction *action, const QString &shortcutText);