mirror of
https://github.com/amnezia-vpn/amnezia-client.git
synced 2026-06-22 02:01:08 +07:00
fixed update icon windows
This commit is contained in:
@@ -100,6 +100,7 @@ bool WindowsUtils::isDarkTheme() {
|
|||||||
QSettings settings(
|
QSettings settings(
|
||||||
QStringLiteral("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize"),
|
QStringLiteral("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize"),
|
||||||
QSettings::NativeFormat);
|
QSettings::NativeFormat);
|
||||||
|
settings.sync();
|
||||||
|
|
||||||
if (settings.contains(QStringLiteral("SystemUsesLightTheme"))) {
|
if (settings.contains(QStringLiteral("SystemUsesLightTheme"))) {
|
||||||
return registryUsesDarkTheme(settings, QStringLiteral("SystemUsesLightTheme"));
|
return registryUsesDarkTheme(settings, QStringLiteral("SystemUsesLightTheme"));
|
||||||
|
|||||||
@@ -6,6 +6,15 @@
|
|||||||
|
|
||||||
WinTrayIconBackend::WinTrayIconBackend(QObject *parent) : m_trayIcon(parent)
|
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)
|
void WinTrayIconBackend::setMenu(QMenu *menu)
|
||||||
@@ -25,7 +34,11 @@ void WinTrayIconBackend::show()
|
|||||||
|
|
||||||
void WinTrayIconBackend::applyVisual(const TrayIconVisual &visual)
|
void WinTrayIconBackend::applyVisual(const TrayIconVisual &visual)
|
||||||
{
|
{
|
||||||
|
m_lastVisual = visual;
|
||||||
WinTrayIcon::applyTo(m_trayIcon, visual.connectionState, visual.darkTheme);
|
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,
|
void WinTrayIconBackend::showMessage(const QString &title, const QString &message, const TrayIconVisual &visual,
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
#include <QColor>
|
#include <QColor>
|
||||||
#include <QIcon>
|
#include <QIcon>
|
||||||
#include <QSystemTrayIcon>
|
#include <QSystemTrayIcon>
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
class WinTrayIconBackend final : public TrayIconBackend
|
class WinTrayIconBackend final : public TrayIconBackend
|
||||||
{
|
{
|
||||||
@@ -21,7 +22,12 @@ public:
|
|||||||
void setActivatedHandler(std::function<void(QSystemTrayIcon::ActivationReason)> handler) override;
|
void setActivatedHandler(std::function<void(QSystemTrayIcon::ActivationReason)> handler) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void reapplyLastVisual();
|
||||||
|
|
||||||
QSystemTrayIcon m_trayIcon;
|
QSystemTrayIcon m_trayIcon;
|
||||||
|
TrayIconVisual m_lastVisual;
|
||||||
|
QTimer m_reapplyTimerShort;
|
||||||
|
QTimer m_reapplyTimerLong;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // WINTRAYICONBACKEND_H
|
#endif // WINTRAYICONBACKEND_H
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
#include <QGuiApplication>
|
#include <QGuiApplication>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QStyleHints>
|
#include <QStyleHints>
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
void WinTrayTheme::installThemeObserver(const std::function<void()> &onThemeChanged, QObject *parent)
|
void WinTrayTheme::installThemeObserver(const std::function<void()> &onThemeChanged, QObject *parent)
|
||||||
{
|
{
|
||||||
@@ -14,15 +15,18 @@ void WinTrayTheme::installThemeObserver(const std::function<void()> &onThemeChan
|
|||||||
return;
|
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()) {
|
if (QStyleHints *styleHints = QGuiApplication::styleHints()) {
|
||||||
QObject::connect(styleHints, &QStyleHints::colorSchemeChanged, parent, [onThemeChanged]() {
|
QObject::connect(styleHints, &QStyleHints::colorSchemeChanged, parent,
|
||||||
onThemeChanged();
|
[schedule](Qt::ColorScheme) { schedule(); });
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
qApp->installEventFilter(new TrayThemeChangeFilter([onThemeChanged]() {
|
qApp->installEventFilter(new TrayThemeChangeFilter([schedule]() { schedule(); }, parent));
|
||||||
onThemeChanged();
|
|
||||||
}, parent));
|
|
||||||
|
|
||||||
WindowsUtils::installThemeChangeObserver(onThemeChanged);
|
WindowsUtils::installThemeChangeObserver([schedule]() { schedule(); });
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -105,9 +105,6 @@ void SystemTrayNotificationHandler::updateTrayIcon()
|
|||||||
}
|
}
|
||||||
|
|
||||||
m_trayIcon->applyVisual(currentTrayVisual());
|
m_trayIcon->applyVisual(currentTrayVisual());
|
||||||
#if defined(Q_OS_WIN)
|
|
||||||
qDebug() << "Windows tray: setIcon darkTheme=" << m_isDarkTheme << "state=" << static_cast<int>(m_trayState);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SystemTrayNotificationHandler::onTrayActivated(QSystemTrayIcon::ActivationReason reason)
|
void SystemTrayNotificationHandler::onTrayActivated(QSystemTrayIcon::ActivationReason reason)
|
||||||
|
|||||||
Reference in New Issue
Block a user