Skip to content

Commit

Permalink
UI: Fix tray icon animation switching
Browse files Browse the repository at this point in the history
  • Loading branch information
tnodir committed Dec 29, 2023
1 parent f7ab740 commit 1b6283e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 10 deletions.
37 changes: 27 additions & 10 deletions src/ui/form/tray/trayicon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions src/ui/form/tray/trayicon.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ protected slots:

void sendAlertMessage();
void updateAlertTimer();

void setupAlertTimer();
void removeAlertTimer();

void updateTrayIconShape();

void addHotKey(QAction *action, const QString &shortcutText);
Expand Down

0 comments on commit 1b6283e

Please sign in to comment.