mirror of
https://github.com/amnezia-vpn/amnezia-client.git
synced 2026-06-20 02:00:55 +07:00
fixed update icon windows
This commit is contained in:
@@ -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"));
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <QColor>
|
||||
#include <QIcon>
|
||||
#include <QSystemTrayIcon>
|
||||
#include <QTimer>
|
||||
|
||||
class WinTrayIconBackend final : public TrayIconBackend
|
||||
{
|
||||
@@ -21,7 +22,12 @@ public:
|
||||
void setActivatedHandler(std::function<void(QSystemTrayIcon::ActivationReason)> handler) override;
|
||||
|
||||
private:
|
||||
void reapplyLastVisual();
|
||||
|
||||
QSystemTrayIcon m_trayIcon;
|
||||
TrayIconVisual m_lastVisual;
|
||||
QTimer m_reapplyTimerShort;
|
||||
QTimer m_reapplyTimerLong;
|
||||
};
|
||||
|
||||
#endif // WINTRAYICONBACKEND_H
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <QGuiApplication>
|
||||
#include <QObject>
|
||||
#include <QStyleHints>
|
||||
#include <QTimer>
|
||||
|
||||
void WinTrayTheme::installThemeObserver(const std::function<void()> &onThemeChanged, QObject *parent)
|
||||
{
|
||||
@@ -14,15 +15,18 @@ void WinTrayTheme::installThemeObserver(const std::function<void()> &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(); });
|
||||
}
|
||||
|
||||
@@ -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<int>(m_trayState);
|
||||
#endif
|
||||
}
|
||||
|
||||
void SystemTrayNotificationHandler::onTrayActivated(QSystemTrayIcon::ActivationReason reason)
|
||||
|
||||
Reference in New Issue
Block a user