diff --git a/client/platforms/windows/windowsutils.cpp b/client/platforms/windows/windowsutils.cpp index 74a3f0d75..b4bc86c92 100644 --- a/client/platforms/windows/windowsutils.cpp +++ b/client/platforms/windows/windowsutils.cpp @@ -100,6 +100,7 @@ bool WindowsUtils::isDarkTheme() { QSettings settings( QStringLiteral("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize"), QSettings::NativeFormat); + settings.sync(); if (settings.contains(QStringLiteral("SystemUsesLightTheme"))) { return registryUsesDarkTheme(settings, QStringLiteral("SystemUsesLightTheme")); diff --git a/client/platforms/windows/wintrayiconbackend.cpp b/client/platforms/windows/wintrayiconbackend.cpp index 0c4451c72..461262cdc 100644 --- a/client/platforms/windows/wintrayiconbackend.cpp +++ b/client/platforms/windows/wintrayiconbackend.cpp @@ -6,6 +6,15 @@ WinTrayIconBackend::WinTrayIconBackend(QObject *parent) : m_trayIcon(parent) { + m_reapplyTimerShort.setSingleShot(true); + m_reapplyTimerLong.setSingleShot(true); + QObject::connect(&m_reapplyTimerShort, &QTimer::timeout, &m_trayIcon, [this]() { reapplyLastVisual(); }); + QObject::connect(&m_reapplyTimerLong, &QTimer::timeout, &m_trayIcon, [this]() { reapplyLastVisual(); }); +} + +void WinTrayIconBackend::reapplyLastVisual() +{ + WinTrayIcon::applyTo(m_trayIcon, m_lastVisual.connectionState, m_lastVisual.darkTheme); } void WinTrayIconBackend::setMenu(QMenu *menu) @@ -25,7 +34,11 @@ void WinTrayIconBackend::show() void WinTrayIconBackend::applyVisual(const TrayIconVisual &visual) { + m_lastVisual = visual; WinTrayIcon::applyTo(m_trayIcon, visual.connectionState, visual.darkTheme); + + m_reapplyTimerShort.start(250); + m_reapplyTimerLong.start(1200); } void WinTrayIconBackend::showMessage(const QString &title, const QString &message, const TrayIconVisual &visual, diff --git a/client/platforms/windows/wintrayiconbackend.h b/client/platforms/windows/wintrayiconbackend.h index 618b29cb7..e8bb3b211 100644 --- a/client/platforms/windows/wintrayiconbackend.h +++ b/client/platforms/windows/wintrayiconbackend.h @@ -6,6 +6,7 @@ #include #include #include +#include class WinTrayIconBackend final : public TrayIconBackend { @@ -21,7 +22,12 @@ public: void setActivatedHandler(std::function handler) override; private: + void reapplyLastVisual(); + QSystemTrayIcon m_trayIcon; + TrayIconVisual m_lastVisual; + QTimer m_reapplyTimerShort; + QTimer m_reapplyTimerLong; }; #endif // WINTRAYICONBACKEND_H diff --git a/client/platforms/windows/wintraytheme.cpp b/client/platforms/windows/wintraytheme.cpp index 933b41be9..945ea4d19 100644 --- a/client/platforms/windows/wintraytheme.cpp +++ b/client/platforms/windows/wintraytheme.cpp @@ -7,6 +7,7 @@ #include #include #include +#include void WinTrayTheme::installThemeObserver(const std::function &onThemeChanged, QObject *parent) { @@ -14,15 +15,18 @@ void WinTrayTheme::installThemeObserver(const std::function &onThemeChan return; } + auto *debounce = new QTimer(parent); + debounce->setSingleShot(true); + QObject::connect(debounce, &QTimer::timeout, parent, [onThemeChanged]() { onThemeChanged(); }); + + const auto schedule = [debounce]() { debounce->start(150); }; + if (QStyleHints *styleHints = QGuiApplication::styleHints()) { - QObject::connect(styleHints, &QStyleHints::colorSchemeChanged, parent, [onThemeChanged]() { - onThemeChanged(); - }); + QObject::connect(styleHints, &QStyleHints::colorSchemeChanged, parent, + [schedule](Qt::ColorScheme) { schedule(); }); } - qApp->installEventFilter(new TrayThemeChangeFilter([onThemeChanged]() { - onThemeChanged(); - }, parent)); + qApp->installEventFilter(new TrayThemeChangeFilter([schedule]() { schedule(); }, parent)); - WindowsUtils::installThemeChangeObserver(onThemeChanged); + WindowsUtils::installThemeChangeObserver([schedule]() { schedule(); }); } diff --git a/client/ui/utils/systemTrayNotificationHandler.cpp b/client/ui/utils/systemTrayNotificationHandler.cpp index 86a4d32af..a4d24e298 100644 --- a/client/ui/utils/systemTrayNotificationHandler.cpp +++ b/client/ui/utils/systemTrayNotificationHandler.cpp @@ -105,9 +105,6 @@ void SystemTrayNotificationHandler::updateTrayIcon() } m_trayIcon->applyVisual(currentTrayVisual()); -#if defined(Q_OS_WIN) - qDebug() << "Windows tray: setIcon darkTheme=" << m_isDarkTheme << "state=" << static_cast(m_trayState); -#endif } void SystemTrayNotificationHandler::onTrayActivated(QSystemTrayIcon::ActivationReason reason)