mirror of
https://github.com/amnezia-vpn/amnezia-client.git
synced 2026-06-24 02:00:24 +07:00
fixed update icon windows & ref code
This commit is contained in:
@@ -312,6 +312,7 @@ if(APPLE AND MACOS_NE)
|
|||||||
${CLIENT_ROOT_DIR}/ui/utils/platformTrayTheme.h
|
${CLIENT_ROOT_DIR}/ui/utils/platformTrayTheme.h
|
||||||
${CLIENT_ROOT_DIR}/ui/utils/trayIconCommon.h
|
${CLIENT_ROOT_DIR}/ui/utils/trayIconCommon.h
|
||||||
${CLIENT_ROOT_DIR}/platforms/windows/wintrayiconbackend.h
|
${CLIENT_ROOT_DIR}/platforms/windows/wintrayiconbackend.h
|
||||||
|
${CLIENT_ROOT_DIR}/platforms/windows/wintrayicon.h
|
||||||
${CLIENT_ROOT_DIR}/platforms/windows/wintraytheme.h
|
${CLIENT_ROOT_DIR}/platforms/windows/wintraytheme.h
|
||||||
${CLIENT_ROOT_DIR}/ui/utils/trayThemeChangeFilter.h
|
${CLIENT_ROOT_DIR}/ui/utils/trayThemeChangeFilter.h
|
||||||
)
|
)
|
||||||
@@ -322,6 +323,7 @@ if(APPLE AND MACOS_NE)
|
|||||||
${CLIENT_ROOT_DIR}/ui/utils/platformTrayTheme.cpp
|
${CLIENT_ROOT_DIR}/ui/utils/platformTrayTheme.cpp
|
||||||
${CLIENT_ROOT_DIR}/ui/utils/trayIconCommon.cpp
|
${CLIENT_ROOT_DIR}/ui/utils/trayIconCommon.cpp
|
||||||
${CLIENT_ROOT_DIR}/platforms/windows/wintrayiconbackend.cpp
|
${CLIENT_ROOT_DIR}/platforms/windows/wintrayiconbackend.cpp
|
||||||
|
${CLIENT_ROOT_DIR}/platforms/windows/wintrayicon.cpp
|
||||||
${CLIENT_ROOT_DIR}/platforms/windows/wintraytheme.cpp
|
${CLIENT_ROOT_DIR}/platforms/windows/wintraytheme.cpp
|
||||||
${CLIENT_ROOT_DIR}/ui/utils/trayThemeChangeFilter.cpp
|
${CLIENT_ROOT_DIR}/ui/utils/trayThemeChangeFilter.cpp
|
||||||
)
|
)
|
||||||
@@ -331,12 +333,14 @@ if(WIN32)
|
|||||||
set(HEADERS ${HEADERS}
|
set(HEADERS ${HEADERS}
|
||||||
${CLIENT_ROOT_DIR}/platforms/windows/windowsutils.h
|
${CLIENT_ROOT_DIR}/platforms/windows/windowsutils.h
|
||||||
${CLIENT_ROOT_DIR}/platforms/windows/wintrayiconbackend.h
|
${CLIENT_ROOT_DIR}/platforms/windows/wintrayiconbackend.h
|
||||||
|
${CLIENT_ROOT_DIR}/platforms/windows/wintrayicon.h
|
||||||
${CLIENT_ROOT_DIR}/platforms/windows/wintraytheme.h
|
${CLIENT_ROOT_DIR}/platforms/windows/wintraytheme.h
|
||||||
${CLIENT_ROOT_DIR}/ui/utils/trayThemeChangeFilter.h
|
${CLIENT_ROOT_DIR}/ui/utils/trayThemeChangeFilter.h
|
||||||
)
|
)
|
||||||
set(SOURCES ${SOURCES}
|
set(SOURCES ${SOURCES}
|
||||||
${CLIENT_ROOT_DIR}/platforms/windows/windowsutils.cpp
|
${CLIENT_ROOT_DIR}/platforms/windows/windowsutils.cpp
|
||||||
${CLIENT_ROOT_DIR}/platforms/windows/wintrayiconbackend.cpp
|
${CLIENT_ROOT_DIR}/platforms/windows/wintrayiconbackend.cpp
|
||||||
|
${CLIENT_ROOT_DIR}/platforms/windows/wintrayicon.cpp
|
||||||
${CLIENT_ROOT_DIR}/platforms/windows/wintraytheme.cpp
|
${CLIENT_ROOT_DIR}/platforms/windows/wintraytheme.cpp
|
||||||
${CLIENT_ROOT_DIR}/ui/utils/trayThemeChangeFilter.cpp
|
${CLIENT_ROOT_DIR}/ui/utils/trayThemeChangeFilter.cpp
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -0,0 +1,43 @@
|
|||||||
|
#include "wintrayicon.h"
|
||||||
|
|
||||||
|
#include "ui/utils/trayIconCommon.h"
|
||||||
|
|
||||||
|
#include <QMenu>
|
||||||
|
|
||||||
|
namespace WinTrayIcon
|
||||||
|
{
|
||||||
|
QIcon buildIcon(qreal opacity, bool darkTheme, const QColor &indicatorColor)
|
||||||
|
{
|
||||||
|
return TrayIconCommon::buildIcon(opacity, darkTheme, indicatorColor);
|
||||||
|
}
|
||||||
|
|
||||||
|
void applyTo(QSystemTrayIcon &trayIcon, Vpn::ConnectionState state, bool darkTheme)
|
||||||
|
{
|
||||||
|
const qreal opacity = TrayIconCommon::opacityForState(state);
|
||||||
|
const QColor indicatorColor = TrayIconCommon::indicatorColorForState(state);
|
||||||
|
trayIcon.setIcon(buildIcon(opacity, darkTheme, indicatorColor));
|
||||||
|
}
|
||||||
|
|
||||||
|
QIcon buildNotifyIcon(bool darkTheme)
|
||||||
|
{
|
||||||
|
return buildIcon(TrayIconCommon::kConnectedOpacity, darkTheme,
|
||||||
|
TrayIconCommon::indicatorColorForState(Vpn::ConnectionState::Connected));
|
||||||
|
}
|
||||||
|
|
||||||
|
void configure(QSystemTrayIcon &trayIcon, QMenu *menu, const QString &tooltip)
|
||||||
|
{
|
||||||
|
trayIcon.setContextMenu(menu);
|
||||||
|
trayIcon.setToolTip(tooltip);
|
||||||
|
}
|
||||||
|
|
||||||
|
void show(QSystemTrayIcon &trayIcon)
|
||||||
|
{
|
||||||
|
trayIcon.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
void showMessage(QSystemTrayIcon &trayIcon, const QString &title, const QString &message, bool darkTheme,
|
||||||
|
int timerMsec)
|
||||||
|
{
|
||||||
|
trayIcon.showMessage(title, message, buildNotifyIcon(darkTheme), timerMsec);
|
||||||
|
}
|
||||||
|
} // namespace WinTrayIcon
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
#ifndef WINTRAYICON_H
|
||||||
|
#define WINTRAYICON_H
|
||||||
|
|
||||||
|
#include "core/protocols/vpnProtocol.h"
|
||||||
|
|
||||||
|
#include <QColor>
|
||||||
|
#include <QIcon>
|
||||||
|
#include <QSystemTrayIcon>
|
||||||
|
|
||||||
|
class QMenu;
|
||||||
|
class QString;
|
||||||
|
|
||||||
|
namespace WinTrayIcon
|
||||||
|
{
|
||||||
|
QIcon buildIcon(qreal opacity, bool darkTheme, const QColor &indicatorColor);
|
||||||
|
void applyTo(QSystemTrayIcon &trayIcon, Vpn::ConnectionState state, bool darkTheme);
|
||||||
|
QIcon buildNotifyIcon(bool darkTheme);
|
||||||
|
|
||||||
|
void configure(QSystemTrayIcon &trayIcon, QMenu *menu, const QString &tooltip);
|
||||||
|
void show(QSystemTrayIcon &trayIcon);
|
||||||
|
void showMessage(QSystemTrayIcon &trayIcon, const QString &title, const QString &message, bool darkTheme,
|
||||||
|
int timerMsec);
|
||||||
|
} // namespace WinTrayIcon
|
||||||
|
|
||||||
|
#endif // WINTRAYICON_H
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
#include "wintrayiconbackend.h"
|
#include "wintrayiconbackend.h"
|
||||||
|
|
||||||
#include "ui/utils/trayIconCommon.h"
|
#include "platforms/windows/wintrayicon.h"
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
@@ -20,23 +20,18 @@ void WinTrayIconBackend::setToolTip(const QString &tooltip)
|
|||||||
|
|
||||||
void WinTrayIconBackend::show()
|
void WinTrayIconBackend::show()
|
||||||
{
|
{
|
||||||
m_trayIcon.show();
|
WinTrayIcon::show(m_trayIcon);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WinTrayIconBackend::applyVisual(const TrayIconVisual &visual)
|
void WinTrayIconBackend::applyVisual(const TrayIconVisual &visual)
|
||||||
{
|
{
|
||||||
const qreal opacity = TrayIconCommon::opacityForState(visual.connectionState);
|
WinTrayIcon::applyTo(m_trayIcon, visual.connectionState, visual.darkTheme);
|
||||||
const QColor indicatorColor = TrayIconCommon::indicatorColorForState(visual.connectionState);
|
|
||||||
m_trayIcon.setIcon(buildTrayIcon(opacity, visual.darkTheme, indicatorColor));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WinTrayIconBackend::showMessage(const QString &title, const QString &message, const TrayIconVisual &visual,
|
void WinTrayIconBackend::showMessage(const QString &title, const QString &message, const TrayIconVisual &visual,
|
||||||
int timerMsec)
|
int timerMsec)
|
||||||
{
|
{
|
||||||
m_trayIcon.showMessage(title, message,
|
WinTrayIcon::showMessage(m_trayIcon, title, message, visual.darkTheme, timerMsec);
|
||||||
buildTrayIcon(TrayIconCommon::kConnectedOpacity, visual.darkTheme,
|
|
||||||
TrayIconCommon::indicatorColorForState(Vpn::ConnectionState::Connected)),
|
|
||||||
timerMsec);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WinTrayIconBackend::rebuildMenu()
|
void WinTrayIconBackend::rebuildMenu()
|
||||||
@@ -53,11 +48,6 @@ void WinTrayIconBackend::setActivatedHandler(std::function<void(QSystemTrayIcon:
|
|||||||
[handler](QSystemTrayIcon::ActivationReason reason) { handler(reason); });
|
[handler](QSystemTrayIcon::ActivationReason reason) { handler(reason); });
|
||||||
}
|
}
|
||||||
|
|
||||||
QIcon WinTrayIconBackend::buildTrayIcon(qreal opacity, bool darkTheme, const QColor &indicatorColor) const
|
|
||||||
{
|
|
||||||
return TrayIconCommon::buildIcon(opacity, darkTheme, indicatorColor);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::unique_ptr<TrayIconBackend> createTrayIconBackend(QObject *parent)
|
std::unique_ptr<TrayIconBackend> createTrayIconBackend(QObject *parent)
|
||||||
{
|
{
|
||||||
return std::make_unique<WinTrayIconBackend>(parent);
|
return std::make_unique<WinTrayIconBackend>(parent);
|
||||||
|
|||||||
@@ -21,8 +21,6 @@ public:
|
|||||||
void setActivatedHandler(std::function<void(QSystemTrayIcon::ActivationReason)> handler) override;
|
void setActivatedHandler(std::function<void(QSystemTrayIcon::ActivationReason)> handler) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QIcon buildTrayIcon(qreal opacity, bool darkTheme, const QColor &indicatorColor) const;
|
|
||||||
|
|
||||||
QSystemTrayIcon m_trayIcon;
|
QSystemTrayIcon m_trayIcon;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -15,12 +15,14 @@ void WinTrayTheme::installThemeObserver(const std::function<void()> &onThemeChan
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (QStyleHints *styleHints = QGuiApplication::styleHints()) {
|
if (QStyleHints *styleHints = QGuiApplication::styleHints()) {
|
||||||
QObject::connect(styleHints, &QStyleHints::colorSchemeChanged, parent, [onThemeChanged]() { onThemeChanged(); });
|
QObject::connect(styleHints, &QStyleHints::colorSchemeChanged, parent, [onThemeChanged]() {
|
||||||
|
onThemeChanged();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
qApp->installEventFilter(new TrayThemeChangeFilter(onThemeChanged, parent));
|
qApp->installEventFilter(new TrayThemeChangeFilter([onThemeChanged]() {
|
||||||
|
onThemeChanged();
|
||||||
|
}, parent));
|
||||||
|
|
||||||
#if defined(Q_OS_WIN)
|
|
||||||
WindowsUtils::installThemeChangeObserver(onThemeChanged);
|
WindowsUtils::installThemeChangeObserver(onThemeChanged);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
#include "platformTrayTheme.h"
|
#include "platformTrayTheme.h"
|
||||||
|
|
||||||
|
#include <QtGlobal>
|
||||||
|
|
||||||
#if defined(Q_OS_MAC) && !defined(MACOS_NE)
|
#if defined(Q_OS_MAC) && !defined(MACOS_NE)
|
||||||
# include "platforms/macos/mactraytheme.h"
|
# include "platforms/macos/mactraytheme.h"
|
||||||
#elif defined(Q_OS_WIN) || (defined(Q_OS_MAC) && defined(MACOS_NE))
|
#elif defined(Q_OS_WIN) || (defined(Q_OS_MAC) && defined(MACOS_NE))
|
||||||
|
|||||||
@@ -82,7 +82,6 @@ void SystemTrayNotificationHandler::refreshTheme()
|
|||||||
m_isDarkTheme = isDarkTheme;
|
m_isDarkTheme = isDarkTheme;
|
||||||
|
|
||||||
#if defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID)
|
#if defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID)
|
||||||
// Palette can change without gtk/portal settings updating; always repaint on Linux.
|
|
||||||
updateTrayIcon();
|
updateTrayIcon();
|
||||||
#else
|
#else
|
||||||
if (themeChanged) {
|
if (themeChanged) {
|
||||||
@@ -106,6 +105,9 @@ 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)
|
||||||
|
|||||||
@@ -9,7 +9,6 @@
|
|||||||
#include "trayIconBackend.h"
|
#include "trayIconBackend.h"
|
||||||
|
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
#include <QSystemTrayIcon>
|
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
|
|||||||
@@ -5,34 +5,29 @@
|
|||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QSvgRenderer>
|
#include <QSvgRenderer>
|
||||||
|
|
||||||
namespace TrayIconCommon {
|
namespace TrayIconCommon
|
||||||
|
{
|
||||||
qreal opacityForState(Vpn::ConnectionState state)
|
qreal opacityForState(Vpn::ConnectionState state)
|
||||||
{
|
{
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case Vpn::ConnectionState::Connected:
|
case Vpn::ConnectionState::Connected:
|
||||||
case Vpn::ConnectionState::Error:
|
case Vpn::ConnectionState::Error: return kConnectedOpacity;
|
||||||
return kConnectedOpacity;
|
|
||||||
case Vpn::ConnectionState::Disconnected:
|
case Vpn::ConnectionState::Disconnected:
|
||||||
case Vpn::ConnectionState::Preparing:
|
case Vpn::ConnectionState::Preparing:
|
||||||
case Vpn::ConnectionState::Connecting:
|
case Vpn::ConnectionState::Connecting:
|
||||||
case Vpn::ConnectionState::Disconnecting:
|
case Vpn::ConnectionState::Disconnecting:
|
||||||
case Vpn::ConnectionState::Reconnecting:
|
case Vpn::ConnectionState::Reconnecting:
|
||||||
case Vpn::ConnectionState::Unknown:
|
case Vpn::ConnectionState::Unknown:
|
||||||
default:
|
default: return kDisconnectedOpacity;
|
||||||
return kDisconnectedOpacity;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QColor indicatorColorForState(Vpn::ConnectionState state)
|
QColor indicatorColorForState(Vpn::ConnectionState state)
|
||||||
{
|
{
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case Vpn::ConnectionState::Connected:
|
case Vpn::ConnectionState::Connected: return QColor(52, 199, 89);
|
||||||
return QColor(52, 199, 89);
|
case Vpn::ConnectionState::Error: return QColor(235, 87, 87);
|
||||||
case Vpn::ConnectionState::Error:
|
default: return QColor();
|
||||||
return QColor(235, 87, 87);
|
|
||||||
default:
|
|
||||||
return QColor();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,24 +9,24 @@
|
|||||||
|
|
||||||
#include "core/protocols/vpnProtocol.h"
|
#include "core/protocols/vpnProtocol.h"
|
||||||
|
|
||||||
namespace TrayIconCommon {
|
namespace TrayIconCommon
|
||||||
|
{
|
||||||
|
constexpr int kDefaultTrayIconSize = 128;
|
||||||
|
constexpr char kTrayTemplateIconPath[] = ":/images/tray/icon.svg";
|
||||||
|
|
||||||
constexpr int kDefaultTrayIconSize = 128;
|
constexpr qreal kDisconnectedOpacity = 0.5;
|
||||||
constexpr char kTrayTemplateIconPath[] = ":/images/tray/icon.svg";
|
constexpr qreal kConnectedOpacity = 1.0;
|
||||||
|
|
||||||
constexpr qreal kDisconnectedOpacity = 0.5;
|
qreal opacityForState(Vpn::ConnectionState state);
|
||||||
constexpr qreal kConnectedOpacity = 1.0;
|
QColor indicatorColorForState(Vpn::ConnectionState state);
|
||||||
|
|
||||||
qreal opacityForState(Vpn::ConnectionState state);
|
QPixmap renderTemplate(const QString &resourcePath, qreal opacity, int size);
|
||||||
QColor indicatorColorForState(Vpn::ConnectionState state);
|
QPixmap colorizeTemplate(const QPixmap &mask, const QColor &foreground, int size);
|
||||||
|
void drawStatusIndicator(QPainter &painter, const QColor &color, int size);
|
||||||
|
|
||||||
QPixmap renderTemplate(const QString &resourcePath, qreal opacity, int size);
|
QPixmap buildPixmap(int size, qreal opacity, bool darkTheme, const QColor &indicatorColor);
|
||||||
QPixmap colorizeTemplate(const QPixmap &mask, const QColor &foreground, int size);
|
QIcon buildIcon(qreal opacity, bool darkTheme, const QColor &indicatorColor);
|
||||||
void drawStatusIndicator(QPainter &painter, const QColor &color, int size);
|
QByteArray buildTemplatePng(qreal opacity);
|
||||||
|
|
||||||
QPixmap buildPixmap(int size, qreal opacity, bool darkTheme, const QColor &indicatorColor);
|
|
||||||
QIcon buildIcon(qreal opacity, bool darkTheme, const QColor &indicatorColor);
|
|
||||||
QByteArray buildTemplatePng(qreal opacity);
|
|
||||||
|
|
||||||
} // namespace TrayIconCommon
|
} // namespace TrayIconCommon
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user