From 17accd23ac6369713ee91396e61b4783489100a3 Mon Sep 17 00:00:00 2001 From: Ignacio Rodriguez Date: Thu, 21 Jan 2021 22:09:14 +0700 Subject: [PATCH 1/3] Handling pre-main window status notifications --- ChangeLog | 1 + src/gui/src/TrayIcon.cpp | 5 ----- src/gui/src/TrayIcon.h | 13 ++++++++++++- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index c7f518cd1..780f1f46b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,6 +4,7 @@ Bug fixes: - #6900 Remaining SonarCloud reported bug items (test fixed) - #6889 Systray Icon on Ubuntu Auto Start (take 2) - #6910 Don't use the word “Version” for release names because it can lead to errors during update checking. +- #69XX Handling pre-main window creation status notifications =========== v1.13.0-stable diff --git a/src/gui/src/TrayIcon.cpp b/src/gui/src/TrayIcon.cpp index aa494bd8c..f44cfa33c 100644 --- a/src/gui/src/TrayIcon.cpp +++ b/src/gui/src/TrayIcon.cpp @@ -12,8 +12,3 @@ void TrayIcon::tryCreate() const QTimer::singleShot(2500, this, &TrayIcon::tryCreate); } } - -void TrayIcon::set(const QIcon& icon) const -{ - m_pTrayIcon->setIcon(icon); -} diff --git a/src/gui/src/TrayIcon.h b/src/gui/src/TrayIcon.h index c708270c8..39d6e3133 100644 --- a/src/gui/src/TrayIcon.h +++ b/src/gui/src/TrayIcon.h @@ -12,6 +12,15 @@ class TrayIcon : public QObject public: using TConnector = std::function; + TrayIcon() + { + set = [this](const QIcon &icon){ + m_init = [this,icon](){ + this->set(icon); + }; + }; + } + template void create(TActionContainer const &actionContainer, TConnector const &connector) { @@ -30,16 +39,18 @@ public: m_pTrayIcon = std::make_unique(); m_pTrayIcon->setContextMenu(m_pTrayIconMenu.get()); m_pTrayIcon->setToolTip("Synergy"); + set = [this](const QIcon& icon) { m_pTrayIcon->setIcon(icon); }; tryCreate(); } void tryCreate() const; - void set(const QIcon& icon) const; + std::function set; private: std::unique_ptr m_pTrayIcon {}; std::unique_ptr m_pTrayIconMenu {}; TConnector m_connector; + std::function m_init; }; From 5d6c1768dc84ff34c4d08df83e3424a56bee8ded Mon Sep 17 00:00:00 2001 From: Ignacio Rodriguez Date: Thu, 21 Jan 2021 22:14:40 +0700 Subject: [PATCH 2/3] reflecting status post-init --- src/gui/src/TrayIcon.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/gui/src/TrayIcon.h b/src/gui/src/TrayIcon.h index 39d6e3133..86f9b0f3c 100644 --- a/src/gui/src/TrayIcon.h +++ b/src/gui/src/TrayIcon.h @@ -42,6 +42,10 @@ public: set = [this](const QIcon& icon) { m_pTrayIcon->setIcon(icon); }; tryCreate(); + if (m_init) { + m_init(); + m_init = std::function(); + } } void tryCreate() const; From 1dbf35dfba41fbb8721064e33b146864a0b0a8c0 Mon Sep 17 00:00:00 2001 From: Ignacio Rodriguez Date: Thu, 21 Jan 2021 22:32:12 +0700 Subject: [PATCH 3/3] resolved code smell reported --- src/gui/src/TrayIcon.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/gui/src/TrayIcon.h b/src/gui/src/TrayIcon.h index 86f9b0f3c..b9d515537 100644 --- a/src/gui/src/TrayIcon.h +++ b/src/gui/src/TrayIcon.h @@ -14,7 +14,7 @@ public: TrayIcon() { - set = [this](const QIcon &icon){ + m_set = [this](const QIcon &icon){ m_init = [this,icon](){ this->set(icon); }; @@ -39,7 +39,7 @@ public: m_pTrayIcon = std::make_unique(); m_pTrayIcon->setContextMenu(m_pTrayIconMenu.get()); m_pTrayIcon->setToolTip("Synergy"); - set = [this](const QIcon& icon) { m_pTrayIcon->setIcon(icon); }; + m_set = [this](const QIcon& icon) { m_pTrayIcon->setIcon(icon); }; tryCreate(); if (m_init) { @@ -49,12 +49,12 @@ public: } void tryCreate() const; - - std::function set; + void set(const QIcon& icon) const { m_set(icon); } private: - std::unique_ptr m_pTrayIcon {}; - std::unique_ptr m_pTrayIconMenu {}; - TConnector m_connector; - std::function m_init; + std::unique_ptr m_pTrayIcon {}; + std::unique_ptr m_pTrayIconMenu {}; + TConnector m_connector; + std::function m_init; + std::function m_set; };