Handling pre-main window status notifications

This commit is contained in:
Ignacio Rodriguez 2021-01-21 22:09:14 +07:00
parent 6cdd5a0583
commit 17accd23ac
3 changed files with 13 additions and 6 deletions

View file

@ -4,6 +4,7 @@ Bug fixes:
- #6900 Remaining SonarCloud reported bug items (test fixed) - #6900 Remaining SonarCloud reported bug items (test fixed)
- #6889 Systray Icon on Ubuntu Auto Start (take 2) - #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. - #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 v1.13.0-stable

View file

@ -12,8 +12,3 @@ void TrayIcon::tryCreate() const
QTimer::singleShot(2500, this, &TrayIcon::tryCreate); QTimer::singleShot(2500, this, &TrayIcon::tryCreate);
} }
} }
void TrayIcon::set(const QIcon& icon) const
{
m_pTrayIcon->setIcon(icon);
}

View file

@ -12,6 +12,15 @@ class TrayIcon : public QObject
public: public:
using TConnector = std::function<void(QObject const *, const char *)>; using TConnector = std::function<void(QObject const *, const char *)>;
TrayIcon()
{
set = [this](const QIcon &icon){
m_init = [this,icon](){
this->set(icon);
};
};
}
template<typename TActionContainer> template<typename TActionContainer>
void create(TActionContainer const &actionContainer, TConnector const &connector) void create(TActionContainer const &actionContainer, TConnector const &connector)
{ {
@ -30,16 +39,18 @@ public:
m_pTrayIcon = std::make_unique<QSystemTrayIcon>(); m_pTrayIcon = std::make_unique<QSystemTrayIcon>();
m_pTrayIcon->setContextMenu(m_pTrayIconMenu.get()); m_pTrayIcon->setContextMenu(m_pTrayIconMenu.get());
m_pTrayIcon->setToolTip("Synergy"); m_pTrayIcon->setToolTip("Synergy");
set = [this](const QIcon& icon) { m_pTrayIcon->setIcon(icon); };
tryCreate(); tryCreate();
} }
void tryCreate() const; void tryCreate() const;
void set(const QIcon& icon) const; std::function<void(const QIcon& icon)> set;
private: private:
std::unique_ptr<QSystemTrayIcon> m_pTrayIcon {}; std::unique_ptr<QSystemTrayIcon> m_pTrayIcon {};
std::unique_ptr<QMenu> m_pTrayIconMenu {}; std::unique_ptr<QMenu> m_pTrayIconMenu {};
TConnector m_connector; TConnector m_connector;
std::function<void()> m_init;
}; };