diff --git a/src/gui/systemtrayicon.cpp b/src/gui/systemtrayicon.cpp index e2808ad9b..a44925021 100644 --- a/src/gui/systemtrayicon.cpp +++ b/src/gui/systemtrayicon.cpp @@ -1,4 +1,5 @@ #include +#include #include "gui/systemtrayicon.h" #include "gui/formmain.h" @@ -20,6 +21,7 @@ SystemTrayIcon::SystemTrayIcon(const QString &normal_icon, SystemTrayIcon::~SystemTrayIcon() { qDebug("Destroying SystemTrayIcon instance."); + hide(); } bool SystemTrayIcon::isSystemTrayAvailable() { @@ -42,6 +44,19 @@ SystemTrayIcon *SystemTrayIcon::getInstance() { return m_trayIcon; } +void SystemTrayIcon::show_private() { + QSystemTrayIcon::show(); + qDebug("Tray icon displayed."); +} + +void SystemTrayIcon::show() { + // Delay avoids race conditions and tray icon is properly displayed. + qDebug("Showing tray icon with 1000 ms delay."); + QTimer::singleShot(1000, + Qt::CoarseTimer, + this, SLOT(show_private())); +} + void SystemTrayIcon::setNumber(int number) { if (number < 0) { QSystemTrayIcon::setIcon(QIcon(m_normalIcon)); diff --git a/src/gui/systemtrayicon.h b/src/gui/systemtrayicon.h index 33d7a2a4f..b8026da78 100644 --- a/src/gui/systemtrayicon.h +++ b/src/gui/systemtrayicon.h @@ -32,6 +32,10 @@ class SystemTrayIcon : public QSystemTrayIcon { signals: public slots: + void show(); + + private slots: + void show_private(); private: QString m_normalIcon;