Compare commits

..

6 Commits

Author SHA1 Message Date
MrMirDan a1a7a5085b missing unfinished type for RU ts 2026-06-12 12:44:37 +03:00
MrMirDan a1a2f63c23 true updated RU ts 2026-06-12 12:40:58 +03:00
MrMirDan 80584d77e1 updated RU ts (removed vanished) 2026-06-03 16:35:12 +03:00
yp a9861d18b7 fix: wrong index on xray pages (#2669)
* test crash xray

* fixed save config xray

* reset file

* fixed text port & reset file

* fixed textFieldWithHeaderType.textField
2026-06-01 12:22:54 +08:00
lunardunno c14138f031 fix: deleting volumes when cleaning the server (#2673)
* Deleting volumes when cleaning the server

* force the remove volumes
2026-06-01 11:54:34 +08:00
yyy-amnezia 60686fde24 fix: link OpenVPNAdapter statically (#2645)
* fix(ios): link OpenVPNAdapter statically

* chore(conan): simplify openvpnadapter merge process and make everything via XCrun

---------

Co-authored-by: Yaroslav Gurov <ygurov@proton.me>
2026-05-30 13:59:35 +08:00
59 changed files with 591 additions and 5837 deletions
-65
View File
@@ -267,10 +267,6 @@ if(WIN32 OR (APPLE AND NOT IOS AND NOT MACOS_NE) OR (LINUX AND NOT ANDROID))
set(HEADERS ${HEADERS}
${CLIENT_ROOT_DIR}/core/utils/ipcClient.h
${CLIENT_ROOT_DIR}/ui/utils/systemTrayNotificationHandler.h
${CLIENT_ROOT_DIR}/ui/utils/platformTheme.h
${CLIENT_ROOT_DIR}/ui/utils/trayIconBackend.h
${CLIENT_ROOT_DIR}/ui/utils/platformTrayTheme.h
${CLIENT_ROOT_DIR}/ui/utils/trayIconCommon.h
${CLIENT_ROOT_DIR}/core/protocols/openVpnProtocol.h
${CLIENT_ROOT_DIR}/core/protocols/wireGuardProtocol.h
${CLIENT_ROOT_DIR}/core/protocols/xrayProtocol.h
@@ -282,81 +278,20 @@ if(WIN32 OR (APPLE AND NOT IOS AND NOT MACOS_NE) OR (LINUX AND NOT ANDROID))
${CLIENT_ROOT_DIR}/core/utils/ipcClient.cpp
${CLIENT_ROOT_DIR}/mozilla/localsocketcontroller.cpp
${CLIENT_ROOT_DIR}/ui/utils/systemTrayNotificationHandler.cpp
${CLIENT_ROOT_DIR}/ui/utils/platformTheme.cpp
${CLIENT_ROOT_DIR}/ui/utils/platformTrayTheme.cpp
${CLIENT_ROOT_DIR}/ui/utils/trayIconCommon.cpp
${CLIENT_ROOT_DIR}/core/protocols/openVpnProtocol.cpp
${CLIENT_ROOT_DIR}/core/protocols/wireGuardProtocol.cpp
${CLIENT_ROOT_DIR}/core/protocols/xrayProtocol.cpp
${CLIENT_ROOT_DIR}/core/protocols/awgProtocol.cpp
)
if(APPLE AND NOT MACOS_NE)
set(HEADERS ${HEADERS}
${CLIENT_ROOT_DIR}/platforms/macos/mactrayiconbackend.h
${CLIENT_ROOT_DIR}/platforms/macos/mactraytheme.h
)
set(SOURCES ${SOURCES}
${CLIENT_ROOT_DIR}/platforms/macos/mactrayiconbackend.mm
${CLIENT_ROOT_DIR}/platforms/macos/mactraytheme.cpp
)
endif()
endif()
if(APPLE AND MACOS_NE)
# Include only the tray notification handler in NE builds
set(HEADERS ${HEADERS}
${CLIENT_ROOT_DIR}/ui/utils/systemTrayNotificationHandler.h
${CLIENT_ROOT_DIR}/ui/utils/platformTheme.h
${CLIENT_ROOT_DIR}/ui/utils/trayIconBackend.h
${CLIENT_ROOT_DIR}/ui/utils/platformTrayTheme.h
${CLIENT_ROOT_DIR}/ui/utils/trayIconCommon.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}/ui/utils/trayThemeChangeFilter.h
)
set(SOURCES ${SOURCES}
${CLIENT_ROOT_DIR}/ui/utils/systemTrayNotificationHandler.cpp
${CLIENT_ROOT_DIR}/ui/utils/platformTheme.cpp
${CLIENT_ROOT_DIR}/ui/utils/platformTrayTheme.cpp
${CLIENT_ROOT_DIR}/ui/utils/trayIconCommon.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}/ui/utils/trayThemeChangeFilter.cpp
)
endif()
if(WIN32)
set(HEADERS ${HEADERS}
${CLIENT_ROOT_DIR}/platforms/windows/windowsutils.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}/ui/utils/trayThemeChangeFilter.h
)
set(SOURCES ${SOURCES}
${CLIENT_ROOT_DIR}/platforms/windows/windowsutils.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}/ui/utils/trayThemeChangeFilter.cpp
)
endif()
if(LINUX)
set(HEADERS ${HEADERS}
${CLIENT_ROOT_DIR}/platforms/linux/linuxutils.h
${CLIENT_ROOT_DIR}/platforms/linux/linuxtrayiconbackend.h
${CLIENT_ROOT_DIR}/platforms/linux/linuxtraytheme.h
${CLIENT_ROOT_DIR}/ui/utils/trayThemeChangeFilter.h
)
set(SOURCES ${SOURCES}
${CLIENT_ROOT_DIR}/platforms/linux/linuxutils.cpp
${CLIENT_ROOT_DIR}/platforms/linux/linuxtrayiconbackend.cpp
${CLIENT_ROOT_DIR}/platforms/linux/linuxtraytheme.cpp
${CLIENT_ROOT_DIR}/ui/utils/trayThemeChangeFilter.cpp
)
endif()
@@ -425,12 +425,7 @@ void CoreSignalHandlers::initNotificationHandler()
auto* trayHandler = qobject_cast<SystemTrayNotificationHandler*>(m_coreController->m_notificationHandler);
connect(m_coreController, &CoreController::websiteUrlChanged, trayHandler, &SystemTrayNotificationHandler::updateWebsiteUrl);
connect(m_coreController->m_connectionUiController, &ConnectionUiController::connectionErrorOccurred, trayHandler,
&SystemTrayNotificationHandler::setConnectionError);
connect(m_coreController->m_pageController, &PageController::errorMessageClosed, trayHandler,
&SystemTrayNotificationHandler::clearConnectionError);
#endif
#endif
}
void CoreSignalHandlers::initUpdateFoundHandler()
+3 -6
View File
@@ -65,12 +65,9 @@
<file>controls/text-cursor.svg</file>
<file>controls/trash.svg</file>
<file>controls/x-circle.svg</file>
<file>tray/off-black.svg</file>
<file>tray/off-light.svg</file>
<file>tray/on-black.svg</file>
<file>tray/on-white.svg</file>
<file>tray/error-black.svg</file>
<file>tray/error-white.svg</file>
<file>tray/active.png</file>
<file>tray/default.png</file>
<file>tray/error.png</file>
<file>controls/monitor.svg</file>
</qresource>
</RCC>
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 8.4 KiB

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 8.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 7.8 KiB

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 7.6 KiB

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 6.5 KiB

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 6.5 KiB

-8
View File
@@ -15,10 +15,6 @@
#include "platforms/ios/QtAppDelegate-C-Interface.h"
#endif
#if defined(Q_OS_MAC) && !defined(MACOS_NE)
#include "platforms/macos/macosutils.h"
#endif
#if !defined(Q_OS_ANDROID) && !defined(Q_OS_IOS) && !defined(MACOS_NE)
bool isAnotherInstanceRunning()
{
@@ -50,10 +46,6 @@ int main(int argc, char *argv[])
AmneziaApplication app(argc, argv);
OsSignalHandler::setup();
#if defined(Q_OS_MAC) && !defined(MACOS_NE)
MacOSUtils::patchNSStatusBarSetImageForBigSur();
#endif
ssh_init();
QObject::connect(&app, &QCoreApplication::aboutToQuit, []() {
ssh_finalize();
@@ -1,81 +0,0 @@
#include "linuxtrayiconbackend.h"
#include "ui/utils/trayIconCommon.h"
#include <QObject>
namespace
{
constexpr int kLinuxTrayIconSizes[] = { 16, 22, 24, 32, 48, 64, 128 };
} // namespace
LinuxTrayIconBackend::LinuxTrayIconBackend(QObject *parent) : m_trayIcon(parent)
{
}
void LinuxTrayIconBackend::setMenu(QMenu *menu)
{
m_trayIcon.setContextMenu(menu);
}
void LinuxTrayIconBackend::setToolTip(const QString &tooltip)
{
m_trayIcon.setToolTip(tooltip);
}
void LinuxTrayIconBackend::show()
{
m_trayIcon.show();
}
void LinuxTrayIconBackend::applyVisual(const TrayIconVisual &visual)
{
if (m_hasLastVisual && visual.connectionState == m_lastState && visual.darkTheme == m_lastDarkTheme) {
return;
}
m_lastState = visual.connectionState;
m_lastDarkTheme = visual.darkTheme;
m_hasLastVisual = true;
const QIcon icon = buildTrayIcon(visual.connectionState, visual.darkTheme);
m_trayIcon.setIcon(icon);
}
void LinuxTrayIconBackend::showMessage(const QString &title, const QString &message, const TrayIconVisual &visual,
int timerMsec)
{
m_trayIcon.showMessage(title, message,
buildTrayIcon(Vpn::ConnectionState::Connected, visual.darkTheme),
timerMsec);
}
void LinuxTrayIconBackend::rebuildMenu()
{
}
void LinuxTrayIconBackend::setActivatedHandler(std::function<void(QSystemTrayIcon::ActivationReason)> handler)
{
if (!handler) {
return;
}
QObject::connect(&m_trayIcon, &QSystemTrayIcon::activated, m_trayIcon.parent(),
[handler](QSystemTrayIcon::ActivationReason reason) { handler(reason); });
}
QIcon LinuxTrayIconBackend::buildTrayIcon(Vpn::ConnectionState state, bool darkTheme) const
{
QIcon icon;
for (int size : kLinuxTrayIconSizes) {
icon.addPixmap(TrayIconCommon::buildPixmap(size, state, darkTheme));
}
return icon;
}
std::unique_ptr<TrayIconBackend> createTrayIconBackend(QObject *parent)
{
return std::make_unique<LinuxTrayIconBackend>(parent);
}
@@ -1,33 +0,0 @@
#ifndef LINUXTRAYICONBACKEND_H
#define LINUXTRAYICONBACKEND_H
#include "ui/utils/trayIconBackend.h"
#include <QColor>
#include <QIcon>
#include <QString>
#include <QSystemTrayIcon>
class LinuxTrayIconBackend final : public TrayIconBackend
{
public:
explicit LinuxTrayIconBackend(QObject *parent);
void setMenu(QMenu *menu) override;
void setToolTip(const QString &tooltip) override;
void show() override;
void applyVisual(const TrayIconVisual &visual) override;
void showMessage(const QString &title, const QString &message, const TrayIconVisual &visual, int timerMsec) override;
void rebuildMenu() override;
void setActivatedHandler(std::function<void(QSystemTrayIcon::ActivationReason)> handler) override;
private:
QIcon buildTrayIcon(Vpn::ConnectionState state, bool darkTheme) const;
QSystemTrayIcon m_trayIcon;
Vpn::ConnectionState m_lastState = Vpn::ConnectionState::Unknown;
bool m_lastDarkTheme = false;
bool m_hasLastVisual = false;
};
#endif // LINUXTRAYICONBACKEND_H
-24
View File
@@ -1,24 +0,0 @@
#include "linuxtraytheme.h"
#include "platforms/linux/linuxutils.h"
#include "ui/utils/trayThemeChangeFilter.h"
#include <QApplication>
#include <QGuiApplication>
#include <QObject>
#include <QStyleHints>
void LinuxTrayTheme::installThemeObserver(const std::function<void()> &onThemeChanged, QObject *parent)
{
if (!onThemeChanged || !parent) {
return;
}
if (QStyleHints *styleHints = QGuiApplication::styleHints()) {
QObject::connect(styleHints, &QStyleHints::colorSchemeChanged, parent, [onThemeChanged]() { onThemeChanged(); });
}
qApp->installEventFilter(new TrayThemeChangeFilter(onThemeChanged, parent));
LinuxUtils::installThemeChangeObserver(onThemeChanged);
}
-15
View File
@@ -1,15 +0,0 @@
#ifndef LINUXTRAYTHEME_H
#define LINUXTRAYTHEME_H
#include <functional>
class QObject;
namespace LinuxTrayTheme
{
void installThemeObserver(const std::function<void()> &onThemeChanged, QObject *parent);
} // namespace LinuxTrayTheme
#endif // LINUXTRAYTHEME_H
-128
View File
@@ -1,128 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "linuxutils.h"
#include <QApplication>
#include <QDBusConnection>
#include <QDBusVariant>
#include <QGuiApplication>
#include <QPalette>
#include <QSettings>
#include <QStyleHints>
namespace {
bool paletteSuggestsDarkTheme()
{
const QPalette palette = QGuiApplication::palette();
const int windowLightness = palette.color(QPalette::Window).lightness();
const int textLightness = palette.color(QPalette::WindowText).lightness();
if (textLightness - windowLightness > 50) {
return true;
}
if (windowLightness - textLightness > 50) {
return false;
}
return windowLightness < 128;
}
class LinuxThemeObserver final : public QObject {
Q_OBJECT
public:
explicit LinuxThemeObserver(std::function<void()> callback, QObject *parent = nullptr)
: QObject(parent)
, m_callback(std::move(callback))
{
QDBusConnection bus = QDBusConnection::sessionBus();
if (!bus.isConnected()) {
return;
}
bus.connect(QStringLiteral("org.freedesktop.portal.Desktop"),
QStringLiteral("/org/freedesktop/portal/desktop"),
QStringLiteral("org.freedesktop.portal.Settings"),
QStringLiteral("SettingChanged"),
this,
SLOT(onPortalSettingChanged(QString, QString, QDBusVariant)));
}
void setCallback(std::function<void()> callback)
{
m_callback = std::move(callback);
}
private slots:
void onPortalSettingChanged(const QString &namespaceName, const QString &key, const QDBusVariant &value)
{
Q_UNUSED(value);
if (namespaceName == QStringLiteral("org.freedesktop.appearance")
&& key == QStringLiteral("color-scheme") && m_callback) {
m_callback();
}
}
private:
std::function<void()> m_callback;
};
LinuxThemeObserver *g_themeObserver = nullptr;
} // namespace
bool LinuxUtils::isDarkTheme()
{
if (QStyleHints *styleHints = QGuiApplication::styleHints()) {
switch (styleHints->colorScheme()) {
case Qt::ColorScheme::Dark:
return true;
case Qt::ColorScheme::Light:
return false;
case Qt::ColorScheme::Unknown:
default:
break;
}
}
QSettings settings(QSettings::IniFormat, QSettings::UserScope, QStringLiteral("gtk-3.0"),
QStringLiteral("settings"));
const QString themeName = settings.value(QStringLiteral("gtk-theme-name")).toString();
if (themeName.contains(QStringLiteral("dark"), Qt::CaseInsensitive)) {
return true;
}
if (themeName.contains(QStringLiteral("light"), Qt::CaseInsensitive)) {
return false;
}
QSettings kdeSettings(QSettings::IniFormat, QSettings::UserScope, QStringLiteral("kdeglobals"));
const QString colorScheme = kdeSettings.value(QStringLiteral("General/ColorScheme")).toString();
if (colorScheme.contains(QStringLiteral("dark"), Qt::CaseInsensitive)) {
return true;
}
if (colorScheme.contains(QStringLiteral("light"), Qt::CaseInsensitive)) {
return false;
}
return paletteSuggestsDarkTheme();
}
void LinuxUtils::installThemeChangeObserver(std::function<void()> callback)
{
if (!callback) {
return;
}
if (!g_themeObserver) {
g_themeObserver = new LinuxThemeObserver(std::move(callback), qApp);
return;
}
g_themeObserver->setCallback(std::move(callback));
}
#include "linuxutils.moc"
-19
View File
@@ -1,19 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef LINUXUTILS_H
#define LINUXUTILS_H
#include <functional>
class LinuxUtils final {
public:
static bool isDarkTheme();
static void installThemeChangeObserver(std::function<void()> callback);
private:
LinuxUtils() = default;
};
#endif // LINUXUTILS_H
+2 -10
View File
@@ -5,12 +5,8 @@
#ifndef MACOSSTATUSICON_H
#define MACOSSTATUSICON_H
#include <QByteArray>
#include <QColor>
#include <QMenu>
#include <QObject>
#include <QPointer>
#include <QString>
class MacOSStatusIcon final : public QObject {
Q_OBJECT
@@ -22,14 +18,10 @@ class MacOSStatusIcon final : public QObject {
public:
void setIcon(const QString& iconUrl);
void setIconFromData(const QByteArray& imageData, bool asTemplate = true);
void setMenu(QMenu* menu);
void rebuildNativeMenu();
void setIndicatorColor(const QColor& indicatorColor);
void setMenu(NSMenu* statusBarMenu);
void setToolTip(const QString& tooltip);
void showMessage(const QString& title, const QString& message);
private:
QPointer<QMenu> m_qtMenu;
};
#endif // MACOSSTATUSICON_H
+57 -95
View File
@@ -10,38 +10,22 @@
#import <UserNotifications/UserNotifications.h>
#import <QResource>
#include <QAction>
@interface MacOSStatusIconMenuTarget : NSObject {
@public
QAction* action;
}
- (void)triggerAction:(id)sender;
@end
@implementation MacOSStatusIconMenuTarget
- (void)triggerAction:(id)sender {
Q_UNUSED(sender);
if (action) {
action->trigger();
}
}
@end
/**
* Creates a NSStatusItem that holds the tray icon. The icon is set as a
* template image, so the system controls its effective appearance for the
* current menu bar theme. The connection status is baked into the artwork, so
* no separate colored indicator is drawn.
* Creates a NSStatusItem with that can hold an icon. Additionally a NSView is
* set as a subview to the button item of the status item. The view serves as
* an indicator that can be displayed in color eventhough the icon is set as a
* template. In that way we give the system control over its effective
* appearance.
*/
@interface MacOSStatusIconDelegate : NSObject
@property(assign) NSStatusItem* statusItem;
@property(retain) NSMenu* nativeMenu;
@property(retain) NSMutableArray* menuActionTargets;
@property(assign) NSView* statusIndicator;
- (void)setIcon:(NSData*)imageData asTemplate:(BOOL)asTemplate;
- (void)setIcon:(NSData*)imageData;
- (void)setIndicator;
- (void)setIndicatorColor:(NSColor*)color;
- (void)setMenu:(NSMenu*)statusBarMenu;
- (void)setToolTip:(NSString*)tooltip;
- (void)rebuildMenuFromQMenu:(QMenu*)menu;
@end
@implementation MacOSStatusIconDelegate
@@ -52,38 +36,58 @@
*/
- (id)init {
self = [super init];
self.menuActionTargets = [[NSMutableArray alloc] init];
// Create status item
self.statusItem =
[[[NSStatusBar systemStatusBar] statusItemWithLength:NSSquareStatusItemLength] retain];
self.statusItem.visible = true;
// Add the indicator as a subview
[self setIndicator];
return self;
}
- (void)dealloc {
self.nativeMenu = nil;
self.menuActionTargets = nil;
[super dealloc];
}
/**
* Sets the image for the status icon.
*
* @param imageData The data for the icon image.
* @param asTemplate When true the icon is a template image recolored by the
* system for the current menu bar appearance. When false the icon is
* rendered in its original colors (used for the colored error icon).
* @param iconPath The data for the icon image.
*/
- (void)setIcon:(NSData*)imageData asTemplate:(BOOL)asTemplate {
- (void)setIcon:(NSData*)imageData {
NSImage* image = [[NSImage alloc] initWithData:imageData];
[image setTemplate:asTemplate];
[image setTemplate:true];
[self.statusItem.button setImage:image];
[image release];
}
/**
* Adds status indicator as a subview to the status item button.
*/
- (void)setIndicator {
float viewHeight = NSHeight([self.statusItem.button bounds]);
float dotSize = viewHeight * 0.35;
float dotOrigin = (viewHeight - dotSize) * 0.8;
NSView* dot = [[NSView alloc] initWithFrame:NSMakeRect(dotOrigin, dotOrigin, dotSize, dotSize)];
self.statusIndicator = dot;
self.statusIndicator.wantsLayer = true;
self.statusIndicator.layer.cornerRadius = dotSize * 0.5;
[self.statusItem.button addSubview:self.statusIndicator];
[dot release];
}
/**
* Sets the color if the indicator.
*
* @param color The indicator background color.
*/
- (void)setIndicatorColor:(NSColor*)color {
if (self.statusIndicator) {
self.statusIndicator.layer.backgroundColor = color.CGColor;
}
}
/**
* Sets the status bar menu to the status item.
*
@@ -101,44 +105,6 @@
- (void)setToolTip:(NSString*)tooltip {
[self.statusItem.button setToolTip:tooltip];
}
- (void)rebuildMenuFromQMenu:(QMenu*)menu {
[self.menuActionTargets removeAllObjects];
if (self.nativeMenu) {
[self.statusItem setMenu:nil];
self.nativeMenu = nil;
}
if (!menu) {
return;
}
NSMenu* nsMenu = [[NSMenu alloc] initWithTitle:@""];
for (QAction* action : menu->actions()) {
if (action->isSeparator()) {
[nsMenu addItem:[NSMenuItem separatorItem]];
continue;
}
MacOSStatusIconMenuTarget* target = [[MacOSStatusIconMenuTarget alloc] init];
target->action = action;
[self.menuActionTargets addObject:target];
[target release];
NSMenuItem* item = [[NSMenuItem alloc] initWithTitle:action->text().toNSString()
action:@selector(triggerAction:)
keyEquivalent:@""];
[item setTarget:target];
[item setEnabled:action->isEnabled()];
[item setHidden:!action->isVisible()];
[nsMenu addItem:item];
[item release];
}
self.nativeMenu = nsMenu;
[self.statusItem setMenu:nsMenu];
}
@end
namespace {
@@ -172,31 +138,27 @@ void MacOSStatusIcon::setIcon(const QString& iconPath) {
QResource imageResource = QResource(iconPath);
Q_ASSERT(imageResource.isValid());
[m_statusBarIcon setIcon:imageResource.uncompressedData().toNSData() asTemplate:true];
[m_statusBarIcon setIcon:imageResource.uncompressedData().toNSData()];
}
void MacOSStatusIcon::setIconFromData(const QByteArray& imageData, bool asTemplate) {
logger.debug() << "Set icon from rendered data";
void MacOSStatusIcon::setIndicatorColor(const QColor& indicatorColor) {
logger.debug() << "Set indicator color";
if (imageData.isEmpty()) {
if (!indicatorColor.isValid()) {
[m_statusBarIcon setIndicatorColor:[NSColor clearColor]];
return;
}
NSData* data = [NSData dataWithBytes:imageData.constData() length:imageData.size()];
[m_statusBarIcon setIcon:data asTemplate:asTemplate];
NSColor* color = [NSColor colorWithCalibratedRed:indicatorColor.red() / 255.0f
green:indicatorColor.green() / 255.0f
blue:indicatorColor.blue() / 255.0f
alpha:indicatorColor.alpha() / 255.0f];
[m_statusBarIcon setIndicatorColor:color];
}
void MacOSStatusIcon::setMenu(QMenu* menu) {
m_qtMenu = menu;
rebuildNativeMenu();
if (menu) {
connect(menu, &QMenu::aboutToShow, this, [this]() { rebuildNativeMenu(); });
}
}
void MacOSStatusIcon::rebuildNativeMenu() {
[m_statusBarIcon rebuildMenuFromQMenu:m_qtMenu.data()];
void MacOSStatusIcon::setMenu(NSMenu* statusBarMenu) {
logger.debug() << "Set menu";
[m_statusBarIcon setMenu:statusBarMenu];
}
void MacOSStatusIcon::setToolTip(const QString& tooltip) {
@@ -212,7 +174,7 @@ void MacOSStatusIcon::showMessage(const QString& title, const QString& message)
// This is a no-op is authorization has been granted.
[center requestAuthorizationWithOptions:(UNAuthorizationOptionSound | UNAuthorizationOptionAlert |
UNAuthorizationOptionBadge)
completionHandler:^(__unused BOOL granted, NSError* _Nullable error) {
completionHandler:^(BOOL granted, NSError* _Nullable error) {
if (error) {
// Note: This error may happen if the application is not signed.
NSLog(@"Error asking for permission to send notifications %@", error);
-5
View File
@@ -8,8 +8,6 @@
#include <QObject>
#include <QString>
#include <functional>
class MacOSUtils final {
public:
static NSString* appId();
@@ -25,9 +23,6 @@ class MacOSUtils final {
static void showDockIcon();
static void patchNSStatusBarSetImageForBigSur();
static bool isDarkTheme();
static void installInterfaceThemeObserver(std::function<void()> callback);
};
#endif // MACOSUTILS_H
-24
View File
@@ -137,30 +137,6 @@ void MacOSUtils::showDockIcon() {
* Original bug (and sample implementation):
* https://bugreports.qt.io/browse/QTBUG-88600
*/
bool MacOSUtils::isDarkTheme() {
if (@available(macOS 10.14, *)) {
NSAppearanceName appearanceName = [[NSApp effectiveAppearance] name];
return appearanceName && [appearanceName isEqualToString:NSAppearanceNameDarkAqua];
}
return false;
}
void MacOSUtils::installInterfaceThemeObserver(std::function<void()> callback) {
if (!callback) {
return;
}
const std::function<void()> themeCallback = std::move(callback);
NSDistributedNotificationCenter *center = [NSDistributedNotificationCenter defaultCenter];
[center addObserverForName:@"AppleInterfaceThemeChangedNotification"
object:nil
queue:[NSOperationQueue mainQueue]
usingBlock:^(__unused NSNotification *notification) {
themeCallback();
}];
}
void MacOSUtils::patchNSStatusBarSetImageForBigSur() {
Method original = class_getInstanceMethod([NSStatusBarButton class], @selector(setImage:));
Method patched = class_getInstanceMethod([NSStatusBarButton class], @selector(setImagePatched:));
@@ -1,25 +0,0 @@
#ifndef MACTRAYICONBACKEND_H
#define MACTRAYICONBACKEND_H
#include "ui/utils/trayIconBackend.h"
#include "macosstatusicon.h"
class MacTrayIconBackend final : public TrayIconBackend
{
public:
explicit MacTrayIconBackend(QObject *parent);
void setMenu(QMenu *menu) override;
void setToolTip(const QString &tooltip) override;
void show() override;
void applyVisual(const TrayIconVisual &visual) override;
void showMessage(const QString &title, const QString &message, const TrayIconVisual &visual, int timerMsec) override;
void rebuildMenu() override;
void setActivatedHandler(std::function<void(QSystemTrayIcon::ActivationReason)> handler) override;
private:
MacOSStatusIcon m_statusIcon;
};
#endif // MACTRAYICONBACKEND_H
@@ -1,55 +0,0 @@
#include "mactrayiconbackend.h"
#include "ui/utils/trayIconCommon.h"
MacTrayIconBackend::MacTrayIconBackend(QObject *parent)
: m_statusIcon(parent)
{
}
void MacTrayIconBackend::setMenu(QMenu *menu)
{
m_statusIcon.setMenu(menu);
}
void MacTrayIconBackend::setToolTip(const QString &tooltip)
{
m_statusIcon.setToolTip(tooltip);
}
void MacTrayIconBackend::show()
{
}
void MacTrayIconBackend::applyVisual(const TrayIconVisual &visual)
{
if (TrayIconCommon::isColoredState(visual.connectionState)) {
// Error icon carries a red badge: render it in color, not as a template.
m_statusIcon.setIconFromData(TrayIconCommon::buildColorPng(visual.connectionState, visual.darkTheme),
/*asTemplate*/ false);
} else {
m_statusIcon.setIconFromData(TrayIconCommon::buildTemplatePng(visual.connectionState), /*asTemplate*/ true);
}
}
void MacTrayIconBackend::showMessage(const QString &title, const QString &message, const TrayIconVisual &visual, int timerMsec)
{
Q_UNUSED(visual);
Q_UNUSED(timerMsec);
m_statusIcon.showMessage(title, message);
}
void MacTrayIconBackend::rebuildMenu()
{
m_statusIcon.rebuildNativeMenu();
}
void MacTrayIconBackend::setActivatedHandler(std::function<void(QSystemTrayIcon::ActivationReason)> handler)
{
Q_UNUSED(handler);
}
std::unique_ptr<TrayIconBackend> createTrayIconBackend(QObject *parent)
{
return std::make_unique<MacTrayIconBackend>(parent);
}
-10
View File
@@ -1,10 +0,0 @@
#include "mactraytheme.h"
#include <QObject>
void MacTrayTheme::installThemeObserver(const std::function<void()> &onThemeChanged, QObject *parent)
{
Q_UNUSED(onThemeChanged);
Q_UNUSED(parent);
// macOS template tray icons follow the menu bar appearance automatically.
}
-15
View File
@@ -1,15 +0,0 @@
#ifndef MACTRAYTHEME_H
#define MACTRAYTHEME_H
#include <functional>
class QObject;
namespace MacTrayTheme
{
void installThemeObserver(const std::function<void()> &onThemeChanged, QObject *parent);
} // namespace MacTrayTheme
#endif // MACTRAYTHEME_H
+1 -83
View File
@@ -14,41 +14,7 @@
namespace {
Logger logger("WindowsUtils");
constexpr const wchar_t kThemeWatcherClassName[] = L"AmneziaVpnThemeWatcher";
struct ThemeObserverState
{
std::function<void()> callback;
HWND hwnd = nullptr;
};
ThemeObserverState g_themeObserver;
bool registryUsesDarkTheme(const QSettings &settings, const QString &lightThemeKey)
{
if (settings.contains(lightThemeKey)) {
return settings.value(lightThemeKey).toInt() != 1;
}
return false;
}
LRESULT CALLBACK themeWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
Q_UNUSED(wParam);
if (msg == WM_SETTINGCHANGE && lParam != 0) {
const wchar_t *section = reinterpret_cast<const wchar_t *>(lParam);
if (wcscmp(section, L"ImmersiveColorSet") == 0 || wcscmp(section, L"WindowsThemeElement") == 0) {
if (g_themeObserver.callback) {
g_themeObserver.callback();
}
}
}
return DefWindowProcW(hwnd, msg, wParam, lParam);
}
} // namespace
} // namespace
constexpr const int WINDOWS_11_BUILD =
22000; // Build Number of the first release win 11 iso
@@ -94,51 +60,3 @@ QString WindowsUtils::windowsVersion() {
void WindowsUtils::forceCrash() {
RaiseException(0x0000DEAD, EXCEPTION_NONCONTINUABLE, 0, NULL);
}
// static
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"));
}
if (settings.contains(QStringLiteral("AppsUseLightTheme"))) {
return registryUsesDarkTheme(settings, QStringLiteral("AppsUseLightTheme"));
}
logger.warning() << "SystemUsesLightTheme registry key is unavailable; assuming dark theme";
return true;
}
void WindowsUtils::installThemeChangeObserver(std::function<void()> callback)
{
g_themeObserver.callback = std::move(callback);
if (g_themeObserver.hwnd) {
return;
}
HINSTANCE instance = GetModuleHandleW(nullptr);
WNDCLASSW wc = {};
wc.lpfnWndProc = themeWndProc;
wc.hInstance = instance;
wc.lpszClassName = kThemeWatcherClassName;
WNDCLASSW existing = {};
if (!GetClassInfoW(instance, kThemeWatcherClassName, &existing)) {
if (!RegisterClassW(&wc)) {
WindowsUtils::windowsLog("Failed to register theme watcher window class");
return;
}
}
g_themeObserver.hwnd = CreateWindowExW(0, kThemeWatcherClassName, L"AmneziaVpnThemeWatcher", 0, 0, 0, 0, 0,
HWND_MESSAGE, nullptr, instance, nullptr);
if (!g_themeObserver.hwnd) {
WindowsUtils::windowsLog("Failed to create theme watcher window");
}
}
-5
View File
@@ -7,8 +7,6 @@
#include <QString>
#include <functional>
class WindowsUtils final {
public:
static QString getErrorMessage();
@@ -20,9 +18,6 @@ class WindowsUtils final {
// Force an application crash for testing
static void forceCrash();
static bool isDarkTheme();
static void installThemeChangeObserver(std::function<void()> callback);
};
#endif // WINDOWSUTILS_H
-40
View File
@@ -1,40 +0,0 @@
#include "wintrayicon.h"
#include "ui/utils/trayIconCommon.h"
#include <QMenu>
namespace WinTrayIcon
{
QIcon buildIcon(Vpn::ConnectionState state, bool darkTheme)
{
return TrayIconCommon::buildIcon(state, darkTheme);
}
void applyTo(QSystemTrayIcon &trayIcon, Vpn::ConnectionState state, bool darkTheme)
{
trayIcon.setIcon(buildIcon(state, darkTheme));
}
QIcon buildNotifyIcon(bool darkTheme)
{
return buildIcon(Vpn::ConnectionState::Connected, darkTheme);
}
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
-25
View File
@@ -1,25 +0,0 @@
#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(Vpn::ConnectionState state, bool darkTheme);
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,67 +0,0 @@
#include "wintrayiconbackend.h"
#include "platforms/windows/wintrayicon.h"
#include <QObject>
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)
{
m_trayIcon.setContextMenu(menu);
}
void WinTrayIconBackend::setToolTip(const QString &tooltip)
{
m_trayIcon.setToolTip(tooltip);
}
void WinTrayIconBackend::show()
{
WinTrayIcon::show(m_trayIcon);
}
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,
int timerMsec)
{
WinTrayIcon::showMessage(m_trayIcon, title, message, visual.darkTheme, timerMsec);
}
void WinTrayIconBackend::rebuildMenu()
{
}
void WinTrayIconBackend::setActivatedHandler(std::function<void(QSystemTrayIcon::ActivationReason)> handler)
{
if (!handler) {
return;
}
QObject::connect(&m_trayIcon, &QSystemTrayIcon::activated, m_trayIcon.parent(),
[handler](QSystemTrayIcon::ActivationReason reason) { handler(reason); });
}
std::unique_ptr<TrayIconBackend> createTrayIconBackend(QObject *parent)
{
return std::make_unique<WinTrayIconBackend>(parent);
}
@@ -1,33 +0,0 @@
#ifndef WINTRAYICONBACKEND_H
#define WINTRAYICONBACKEND_H
#include "ui/utils/trayIconBackend.h"
#include <QColor>
#include <QIcon>
#include <QSystemTrayIcon>
#include <QTimer>
class WinTrayIconBackend final : public TrayIconBackend
{
public:
explicit WinTrayIconBackend(QObject *parent);
void setMenu(QMenu *menu) override;
void setToolTip(const QString &tooltip) override;
void show() override;
void applyVisual(const TrayIconVisual &visual) override;
void showMessage(const QString &title, const QString &message, const TrayIconVisual &visual, int timerMsec) override;
void rebuildMenu() override;
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
-32
View File
@@ -1,32 +0,0 @@
#include "wintraytheme.h"
#include "platforms/windows/windowsutils.h"
#include "ui/utils/trayThemeChangeFilter.h"
#include <QApplication>
#include <QGuiApplication>
#include <QObject>
#include <QStyleHints>
#include <QTimer>
void WinTrayTheme::installThemeObserver(const std::function<void()> &onThemeChanged, QObject *parent)
{
if (!onThemeChanged || !parent) {
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,
[schedule](Qt::ColorScheme) { schedule(); });
}
qApp->installEventFilter(new TrayThemeChangeFilter([schedule]() { schedule(); }, parent));
WindowsUtils::installThemeChangeObserver([schedule]() { schedule(); });
}
-15
View File
@@ -1,15 +0,0 @@
#ifndef WINTRAYTHEME_H
#define WINTRAYTHEME_H
#include <functional>
class QObject;
namespace WinTrayTheme
{
void installThemeObserver(const std::function<void()> &onThemeChanged, QObject *parent);
} // namespace WinTrayTheme
#endif // WINTRAYTHEME_H
@@ -1,5 +1,6 @@
sudo docker ps -a | grep amnezia | awk '{print $1}' | xargs sudo docker stop;\
sudo docker ps -a | grep amnezia | awk '{print $1}' | xargs sudo docker rm -fv;\
sudo docker images -a --format table | grep amnezia | awk '{print $3, $1 ":" $2}' | xargs sudo docker rmi;\
sudo docker volume ls | grep amnezia | awk '{print $2}' | xargs sudo docker volume rm -f;\
sudo docker network ls | grep amnezia-dns-net | awk '{print $1}' | xargs sudo docker network rm;\
sudo rm -frd /opt/amnezia
File diff suppressed because it is too large Load Diff
@@ -248,8 +248,3 @@ void PageController::onShowErrorMessage(ErrorCode errorCode)
emit showErrorMessage(fullMessage);
}
void PageController::onErrorMessageClosed()
{
emit errorMessageClosed();
}
+2 -2
View File
@@ -133,7 +133,7 @@ public slots:
int getDrawerDepth() const;
int incrementDrawerDepth();
int decrementDrawerDepth();
void onErrorMessageClosed();
bool isEdgeToEdgeEnabled();
int getStatusBarHeight();
int getNavigationBarHeight();
@@ -162,7 +162,7 @@ signals:
void showErrorMessage(amnezia::ErrorCode);
void showErrorMessage(const QString &errorMessage);
void showNotificationMessage(const QString &message);
void errorMessageClosed();
void showBusyIndicator(bool visible);
void disableControls(bool disabled);
void disableTabBar(bool disabled);
@@ -112,7 +112,7 @@ PageType {
return
}
PageController.goToPage(PageEnum.PageSetupWizardInstalling)
InstallController.updateContainer(ServersUiController.processedIndex, ServersUiController.processedContainerIndex, ProtocolEnum.Xray)
InstallController.updateContainer(ServersUiController.processedServerId, ServersUiController.processedContainerIndex, ProtocolEnum.Xray)
}
var noButtonFunction = function () {
if (typeof GC !== "undefined" && !GC.isMobile()) {
@@ -279,7 +279,7 @@ PageType {
return
}
PageController.goToPage(PageEnum.PageSetupWizardInstalling)
InstallController.updateContainer(ServersUiController.processedIndex, ServersUiController.processedContainerIndex, ProtocolEnum.Xray)
InstallController.updateContainer(ServersUiController.processedServerId, ServersUiController.processedContainerIndex, ProtocolEnum.Xray)
}
var noButtonFunction = function () {
if (typeof GC !== "undefined" && !GC.isMobile()) {
@@ -17,6 +17,10 @@ import "../Components"
PageType {
id: root
enableTimer: false
property bool portDirty: false
function formatTransport(value) {
if (value === "raw") return "RAW (TCP)"
if (value === "xhttp") return "XHTTP"
@@ -39,8 +43,8 @@ PageType {
anchors.right: parent.right
anchors.topMargin: 20 + PageController.safeAreaTopMargin
onFocusChanged: {
if (this.activeFocus) {
onActiveFocusChanged: {
if (backButton.enabled && backButton.activeFocus) {
listView.positionViewAtBeginning()
}
}
@@ -60,8 +64,6 @@ PageType {
delegate: ColumnLayout {
width: listView.width
property alias focusItemId: textFieldWithHeaderType.textField
spacing: 0
Text {
@@ -107,13 +109,32 @@ PageType {
Layout.rightMargin: 16
enabled: listView.enabled
headerText: qsTr("Port")
textField.text: port
Binding {
target: textFieldWithHeaderType.textField
property: "text"
value: port
when: !textFieldWithHeaderType.textField.activeFocus
restoreMode: Binding.RestoreNone
}
textField.maximumLength: 5
textField.validator: IntValidator {
bottom: 1; top: 65535
}
textField.onActiveFocusChanged: {
if (textField.activeFocus && textField.text === "" && port !== "") {
textField.text = port
}
}
textField.onTextChanged: {
root.portDirty = (textField.text !== port)
}
textField.onEditingFinished: {
if (textField.text !== port) port = textField.text
if (textField.text !== port) {
port = textField.text
}
root.portDirty = false
}
checkEmptyText: true
}
@@ -172,9 +193,8 @@ PageType {
Layout.leftMargin: 16
Layout.rightMargin: 16
visible: listView.enabled
&& (XrayConfigModel.hasUnsavedChanges
|| textFieldWithHeaderType.textField.text !== port)
enabled: visible && textFieldWithHeaderType.errorText === ""
&& (XrayConfigModel.hasUnsavedChanges || root.portDirty)
enabled: visible && textFieldWithHeaderType.textField.text !== ""
text: qsTr("Save")
onClicked: function() {
forceActiveFocus()
@@ -742,7 +742,7 @@ PageType {
return
}
PageController.goToPage(PageEnum.PageSetupWizardInstalling)
InstallController.updateContainer(ServersUiController.processedIndex, ServersUiController.processedContainerIndex, ProtocolEnum.Xray)
InstallController.updateContainer(ServersUiController.processedServerId, ServersUiController.processedContainerIndex, ProtocolEnum.Xray)
}
var noButtonFunction = function () {
if (typeof GC !== "undefined" && !GC.isMobile()) {
@@ -95,7 +95,7 @@ PageType {
return
}
PageController.goToPage(PageEnum.PageSetupWizardInstalling)
InstallController.updateContainer(ServersUiController.processedIndex, ServersUiController.processedContainerIndex, ProtocolEnum.Xray)
InstallController.updateContainer(ServersUiController.processedServerId, ServersUiController.processedContainerIndex, ProtocolEnum.Xray)
}
var noButtonFunction = function () {
if (typeof GC !== "undefined" && !GC.isMobile()) {
@@ -211,7 +211,7 @@ PageType {
return
}
PageController.goToPage(PageEnum.PageSetupWizardInstalling)
InstallController.updateContainer(ServersUiController.processedIndex, ServersUiController.processedContainerIndex, ProtocolEnum.Xray)
InstallController.updateContainer(ServersUiController.processedServerId, ServersUiController.processedContainerIndex, ProtocolEnum.Xray)
}
var noButtonFunction = function () {
if (typeof GC !== "undefined" && !GC.isMobile()) {
@@ -208,7 +208,7 @@ PageType {
return
}
PageController.goToPage(PageEnum.PageSetupWizardInstalling)
InstallController.updateContainer(ServersUiController.processedIndex, ServersUiController.processedContainerIndex, ProtocolEnum.Xray)
InstallController.updateContainer(ServersUiController.processedServerId, ServersUiController.processedContainerIndex, ProtocolEnum.Xray)
}
var noButtonFunction = function () {
if (typeof GC !== "undefined" && !GC.isMobile()) {
-7
View File
@@ -203,13 +203,6 @@ Window {
PopupType {
id: popupErrorMessage
}
Connections {
target: popupErrorMessage
function onClosed() {
PageController.onErrorMessageClosed()
}
}
}
Item {
-28
View File
@@ -1,28 +0,0 @@
#include "platformTheme.h"
#include <QGuiApplication>
#include <QStyleHints>
#if defined(Q_OS_MAC)
# include "platforms/macos/macosutils.h"
#elif defined(Q_OS_WIN)
# include "platforms/windows/windowsutils.h"
#elif defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID)
# include "platforms/linux/linuxutils.h"
#endif
bool platformIsDarkTheme()
{
#if defined(Q_OS_MAC)
return MacOSUtils::isDarkTheme();
#elif defined(Q_OS_WIN)
return WindowsUtils::isDarkTheme();
#elif defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID)
return LinuxUtils::isDarkTheme();
#else
if (QStyleHints *styleHints = QGuiApplication::styleHints()) {
return styleHints->colorScheme() == Qt::ColorScheme::Dark;
}
return false;
#endif
}
-6
View File
@@ -1,6 +0,0 @@
#ifndef PLATFORMTHEME_H
#define PLATFORMTHEME_H
bool platformIsDarkTheme();
#endif // PLATFORMTHEME_H
-26
View File
@@ -1,26 +0,0 @@
#include "platformTrayTheme.h"
#include <QtGlobal>
#if defined(Q_OS_MAC) && !defined(MACOS_NE)
# include "platforms/macos/mactraytheme.h"
#elif defined(Q_OS_WIN) || (defined(Q_OS_MAC) && defined(MACOS_NE))
# include "platforms/windows/wintraytheme.h"
#elif defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID)
# include "platforms/linux/linuxtraytheme.h"
#endif
void installTrayThemeObserver(const std::function<void()> &onThemeChanged, QObject *parent)
{
if (!onThemeChanged || !parent) {
return;
}
#if defined(Q_OS_MAC) && !defined(MACOS_NE)
MacTrayTheme::installThemeObserver(onThemeChanged, parent);
#elif defined(Q_OS_WIN) || (defined(Q_OS_MAC) && defined(MACOS_NE))
WinTrayTheme::installThemeObserver(onThemeChanged, parent);
#elif defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID)
LinuxTrayTheme::installThemeObserver(onThemeChanged, parent);
#endif
}
-10
View File
@@ -1,10 +0,0 @@
#ifndef PLATFORMTRAYTHEME_H
#define PLATFORMTRAYTHEME_H
#include <functional>
class QObject;
void installTrayThemeObserver(const std::function<void()> &onThemeChanged, QObject *parent);
#endif // PLATFORMTRAYTHEME_H
@@ -5,26 +5,27 @@
#include <QDebug>
#include "systemTrayNotificationHandler.h"
#include "platformTheme.h"
#include "platformTrayTheme.h"
#include "trayIconBackend.h"
#ifdef Q_OS_MAC
# include "platforms/macos/macosutils.h"
#endif
#include <QApplication>
#include <QDesktopServices>
#include <QIcon>
#include <QWindow>
#include "version.h"
SystemTrayNotificationHandler::SystemTrayNotificationHandler(QObject* parent) :
NotificationHandler(parent)
{
m_trayIcon = createTrayIconBackend(this);
m_trayIcon->setMenu(&m_menu);
m_trayIcon->setToolTip(APPLICATION_NAME);
m_trayIcon->setActivatedHandler([this](QSystemTrayIcon::ActivationReason reason) {
onTrayActivated(reason);
});
NotificationHandler(parent),
m_systemTrayIcon(parent)
m_trayActionShow = m_menu.addAction(tr("Show") + " " + APPLICATION_NAME, this, [this](){
{
m_systemTrayIcon.show();
connect(&m_systemTrayIcon, &QSystemTrayIcon::activated, this, &SystemTrayNotificationHandler::onTrayActivated);
m_trayActionShow = m_menu.addAction(QIcon(":/images/tray/application.png"), tr("Show") + " " + APPLICATION_NAME, this, [this](){
emit raiseRequested();
});
m_menu.addSeparator();
@@ -33,22 +34,22 @@ SystemTrayNotificationHandler::SystemTrayNotificationHandler(QObject* parent) :
m_menu.addSeparator();
m_trayActionVisitWebSite = m_menu.addAction(tr("Visit Website"), [&](){
m_trayActionVisitWebSite = m_menu.addAction(QIcon(":/images/tray/link.png"), tr("Visit Website"), [&](){
QDesktopServices::openUrl(QUrl(websiteUrl));
});
m_trayActionQuit = m_menu.addAction(tr("Quit") + " " + APPLICATION_NAME,
// Quit action: disconnect VPN first on macOS NE, else quit directly
m_trayActionQuit = m_menu.addAction(QIcon(":/images/tray/cancel.png"),
tr("Quit") + " " + APPLICATION_NAME,
this,
[&](){ qApp->quit(); });
installTrayThemeObserver([this]() { refreshTheme(); }, this);
m_isDarkTheme = platformIsDarkTheme();
m_systemTrayIcon.setContextMenu(&m_menu);
setTrayState(Vpn::ConnectionState::Disconnected);
m_trayIcon->show();
}
SystemTrayNotificationHandler::~SystemTrayNotificationHandler() = default;
SystemTrayNotificationHandler::~SystemTrayNotificationHandler() {
}
void SystemTrayNotificationHandler::setConnectionState(Vpn::ConnectionState state)
{
@@ -62,65 +63,21 @@ void SystemTrayNotificationHandler::onTranslationsUpdated()
m_trayActionConnect->setText(tr("Connect"));
m_trayActionDisconnect->setText(tr("Disconnect"));
m_trayActionVisitWebSite->setText(tr("Visit Website"));
m_trayActionQuit->setText(tr("Quit") + " " + APPLICATION_NAME);
if (m_trayIcon) {
m_trayIcon->rebuildMenu();
}
m_trayActionQuit->setText(tr("Quit")+ " " + APPLICATION_NAME);
}
void SystemTrayNotificationHandler::updateWebsiteUrl(const QString &newWebsiteUrl)
{
void SystemTrayNotificationHandler::updateWebsiteUrl(const QString &newWebsiteUrl) {
qDebug() << "Updated website URL:" << newWebsiteUrl;
websiteUrl = newWebsiteUrl;
}
void SystemTrayNotificationHandler::refreshTheme()
void SystemTrayNotificationHandler::setTrayIcon(const QString &iconPath)
{
const bool isDarkTheme = platformIsDarkTheme();
const bool themeChanged = (isDarkTheme != m_isDarkTheme);
m_isDarkTheme = isDarkTheme;
#if defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID)
updateTrayIcon();
#else
if (themeChanged) {
updateTrayIcon();
}
QIcon trayIconMask(QPixmap(iconPath).scaled(128,128));
#ifndef Q_OS_MAC
trayIconMask.setIsMask(true);
#endif
}
TrayIconVisual SystemTrayNotificationHandler::currentTrayVisual() const
{
TrayIconVisual visual;
visual.connectionState = m_errorLatched ? Vpn::ConnectionState::Error : m_trayState;
visual.darkTheme = m_isDarkTheme;
return visual;
}
void SystemTrayNotificationHandler::setConnectionError()
{
m_errorLatched = true;
updateTrayIcon();
}
void SystemTrayNotificationHandler::clearConnectionError()
{
if (!m_errorLatched) {
return;
}
m_errorLatched = false;
updateTrayIcon();
}
void SystemTrayNotificationHandler::updateTrayIcon()
{
if (!m_trayIcon) {
return;
}
m_trayIcon->applyVisual(currentTrayVisual());
m_systemTrayIcon.setIcon(trayIconMask);
}
void SystemTrayNotificationHandler::onTrayActivated(QSystemTrayIcon::ActivationReason reason)
@@ -134,48 +91,41 @@ void SystemTrayNotificationHandler::onTrayActivated(QSystemTrayIcon::ActivationR
void SystemTrayNotificationHandler::setTrayState(Vpn::ConnectionState state)
{
if (state == Vpn::ConnectionState::Error || state == Vpn::ConnectionState::Unknown) {
// Latch the error icon. Both Error and Unknown surface the error message
// in the UI. The connection is torn down to Disconnected right after, so
// treat the real state as Disconnected and let the latch keep the error
// icon visible until the error is acknowledged.
m_errorLatched = true;
state = Vpn::ConnectionState::Disconnected;
} else if (state != Vpn::ConnectionState::Disconnected) {
// A new (re)connecting/connected lifecycle clears a previous error.
// Plain Disconnected leaves the latch untouched so the auto-Disconnected
// that immediately follows an error does not drop the error icon.
m_errorLatched = false;
}
m_trayState = state;
QString resourcesPath = ":/images/tray/%1";
switch (state) {
case Vpn::ConnectionState::Disconnected:
setTrayIcon(QString(resourcesPath).arg(DisconnectedTrayIconName));
m_trayActionConnect->setEnabled(true);
m_trayActionDisconnect->setEnabled(false);
break;
case Vpn::ConnectionState::Preparing:
setTrayIcon(QString(resourcesPath).arg(DisconnectedTrayIconName));
m_trayActionConnect->setEnabled(false);
m_trayActionDisconnect->setEnabled(true);
break;
case Vpn::ConnectionState::Connecting:
setTrayIcon(QString(resourcesPath).arg(DisconnectedTrayIconName));
m_trayActionConnect->setEnabled(false);
m_trayActionDisconnect->setEnabled(true);
break;
case Vpn::ConnectionState::Connected:
setTrayIcon(QString(resourcesPath).arg(ConnectedTrayIconName));
m_trayActionConnect->setEnabled(false);
m_trayActionDisconnect->setEnabled(true);
break;
case Vpn::ConnectionState::Disconnecting:
setTrayIcon(QString(resourcesPath).arg(DisconnectedTrayIconName));
m_trayActionConnect->setEnabled(false);
m_trayActionDisconnect->setEnabled(true);
break;
case Vpn::ConnectionState::Reconnecting:
setTrayIcon(QString(resourcesPath).arg(DisconnectedTrayIconName));
m_trayActionConnect->setEnabled(false);
m_trayActionDisconnect->setEnabled(true);
break;
case Vpn::ConnectionState::Error:
setTrayIcon(QString(resourcesPath).arg(ErrorTrayIconName));
m_trayActionConnect->setEnabled(true);
m_trayActionDisconnect->setEnabled(false);
break;
@@ -183,26 +133,41 @@ void SystemTrayNotificationHandler::setTrayState(Vpn::ConnectionState state)
default:
m_trayActionConnect->setEnabled(false);
m_trayActionDisconnect->setEnabled(true);
break;
setTrayIcon(QString(resourcesPath).arg(DisconnectedTrayIconName));
}
updateTrayIcon();
if (m_trayIcon) {
m_trayIcon->rebuildMenu();
}
//#ifdef Q_OS_MAC
// // Get theme from current user (note, this app can be launched as root application and in this case this theme can be different from theme of real current user )
// bool darkTaskBar = MacOSFunctions::instance().isMenuBarUseDarkTheme();
// darkTaskBar = forceUseBrightIcons ? true : darkTaskBar;
// resourcesPath = ":/images_mac/tray_icon/%1";
// useIconName = useIconName.replace(".png", darkTaskBar ? "@2x.png" : " dark@2x.png");
//#endif
}
void SystemTrayNotificationHandler::notify(NotificationHandler::Message type,
const QString& title,
const QString& message,
int timerMsec)
{
Q_UNUSED(type);
int timerMsec) {
Q_UNUSED(type);
if (!m_trayIcon) {
return;
}
m_trayIcon->showMessage(title, message, currentTrayVisual(), timerMsec);
QIcon icon(ConnectedTrayIconName);
m_systemTrayIcon.showMessage(title, message, icon, timerMsec);
}
void SystemTrayNotificationHandler::showHideWindow() {
// QmlEngineHolder* engine = QmlEngineHolder::instance();
// if (engine->window()->isVisible()) {
// engine->hideWindow();
//#ifdef MVPN_MACOS
// MacOSUtils::hideDockIcon();
//#endif
// } else {
// engine->showWindow();
//#ifdef MVPN_MACOS
// MacOSUtils::showDockIcon();
//#endif
// }
}
+14 -18
View File
@@ -6,18 +6,16 @@
#define SYSTEMTRAYNOTIFICATIONHANDLER_H
#include "notificationHandler.h"
#include "trayIconBackend.h"
#include <QMenu>
#include <memory>
#include <QSystemTrayIcon>
class SystemTrayNotificationHandler : public NotificationHandler {
Q_OBJECT
public:
explicit SystemTrayNotificationHandler(QObject* parent);
~SystemTrayNotificationHandler() override;
~SystemTrayNotificationHandler();
void setConnectionState(Vpn::ConnectionState state) override;
@@ -25,37 +23,35 @@ public:
public slots:
void updateWebsiteUrl(const QString &newWebsiteUrl);
void setConnectionError();
void clearConnectionError();
protected:
void notify(Message type, const QString& title,
const QString& message, int timerMsec) override;
virtual void notify(Message type, const QString& title,
const QString& message, int timerMsec) override;
private:
void showHideWindow();
void setTrayState(Vpn::ConnectionState state);
void onTrayActivated(QSystemTrayIcon::ActivationReason reason);
void refreshTheme();
void updateTrayIcon();
TrayIconVisual currentTrayVisual() const;
void setTrayIcon(const QString &iconPath);
private:
QMenu m_menu;
std::unique_ptr<TrayIconBackend> m_trayIcon;
QSystemTrayIcon m_systemTrayIcon;
QAction* m_trayActionShow = nullptr;
QAction* m_trayActionConnect = nullptr;
QAction* m_trayActionDisconnect = nullptr;
QAction* m_trayActionVisitWebSite = nullptr;
QAction* m_trayActionQuit = nullptr;
QAction* m_statusLabel = nullptr;
QAction* m_statusLabel = nullptr;
QAction* m_separator = nullptr;
Vpn::ConnectionState m_trayState = Vpn::ConnectionState::Unknown;
bool m_isDarkTheme = false;
bool m_errorLatched = false;
QString websiteUrl = "https://amnezia.org";
const QString ConnectedTrayIconName = "active.png";
const QString DisconnectedTrayIconName = "default.png";
const QString ErrorTrayIconName = "error.png";
QString websiteUrl = "https://amnezia.org";
};
#endif // SYSTEMTRAYNOTIFICATIONHANDLER_H
-35
View File
@@ -1,35 +0,0 @@
#ifndef TRAYICONBACKEND_H
#define TRAYICONBACKEND_H
#include <functional>
#include <memory>
#include <QMenu>
#include <QString>
#include <QSystemTrayIcon>
#include "core/protocols/vpnProtocol.h"
class QObject;
struct TrayIconVisual {
Vpn::ConnectionState connectionState = Vpn::ConnectionState::Unknown;
bool darkTheme = false;
};
class TrayIconBackend {
public:
virtual ~TrayIconBackend() = default;
virtual void setMenu(QMenu *menu) = 0;
virtual void setToolTip(const QString &tooltip) = 0;
virtual void show() = 0;
virtual void applyVisual(const TrayIconVisual &visual) = 0;
virtual void showMessage(const QString &title, const QString &message, const TrayIconVisual &visual, int timerMsec) = 0;
virtual void rebuildMenu() = 0;
virtual void setActivatedHandler(std::function<void(QSystemTrayIcon::ActivationReason)> handler) = 0;
};
std::unique_ptr<TrayIconBackend> createTrayIconBackend(QObject *parent);
#endif // TRAYICONBACKEND_H
-80
View File
@@ -1,80 +0,0 @@
#include "trayIconCommon.h"
#include <QBuffer>
#include <QDebug>
#include <QPainter>
#include <QSvgRenderer>
namespace TrayIconCommon
{
QString resourcePathForState(Vpn::ConnectionState state, bool darkTheme)
{
switch (state) {
case Vpn::ConnectionState::Error:
return QString::fromLatin1(darkTheme ? kIconErrorWhite : kIconErrorBlack);
case Vpn::ConnectionState::Connected:
return QString::fromLatin1(darkTheme ? kIconOnWhite : kIconOnBlack);
case Vpn::ConnectionState::Disconnected:
case Vpn::ConnectionState::Preparing:
case Vpn::ConnectionState::Connecting:
case Vpn::ConnectionState::Disconnecting:
case Vpn::ConnectionState::Reconnecting:
case Vpn::ConnectionState::Unknown:
default:
return QString::fromLatin1(darkTheme ? kIconOffLight : kIconOffBlack);
}
}
bool isColoredState(Vpn::ConnectionState state)
{
return state == Vpn::ConnectionState::Error;
}
QPixmap renderIcon(const QString &resourcePath, int size)
{
QSvgRenderer renderer(resourcePath);
QPixmap pixmap(size, size);
pixmap.fill(Qt::transparent);
if (!renderer.isValid()) {
qWarning() << "Failed to load tray icon:" << resourcePath;
return pixmap;
}
QPainter painter(&pixmap);
renderer.render(&painter, QRectF(0, 0, size, size));
return pixmap;
}
QPixmap buildPixmap(int size, Vpn::ConnectionState state, bool darkTheme)
{
return renderIcon(resourcePathForState(state, darkTheme), size);
}
QIcon buildIcon(Vpn::ConnectionState state, bool darkTheme)
{
QIcon icon;
icon.addPixmap(buildPixmap(kDefaultTrayIconSize, state, darkTheme));
return icon;
}
QByteArray pixmapToPng(const QPixmap &pixmap)
{
QByteArray bytes;
QBuffer buffer(&bytes);
buffer.open(QIODevice::WriteOnly);
pixmap.save(&buffer, "PNG");
return bytes;
}
QByteArray buildTemplatePng(Vpn::ConnectionState state)
{
return pixmapToPng(renderIcon(resourcePathForState(state, /*darkTheme*/ true), kDefaultTrayIconSize));
}
QByteArray buildColorPng(Vpn::ConnectionState state, bool darkTheme)
{
return pixmapToPng(renderIcon(resourcePathForState(state, darkTheme), kDefaultTrayIconSize));
}
} // namespace TrayIconCommon
-35
View File
@@ -1,35 +0,0 @@
#ifndef TRAYICONCOMMON_H
#define TRAYICONCOMMON_H
#include <QByteArray>
#include <QIcon>
#include <QPixmap>
#include <QString>
#include "core/protocols/vpnProtocol.h"
namespace TrayIconCommon
{
constexpr int kDefaultTrayIconSize = 128;
constexpr char kIconOffBlack[] = ":/images/tray/off-black.svg";
constexpr char kIconOffLight[] = ":/images/tray/off-light.svg";
constexpr char kIconOnBlack[] = ":/images/tray/on-black.svg";
constexpr char kIconOnWhite[] = ":/images/tray/on-white.svg";
constexpr char kIconErrorBlack[] = ":/images/tray/error-black.svg";
constexpr char kIconErrorWhite[] = ":/images/tray/error-white.svg";
QString resourcePathForState(Vpn::ConnectionState state, bool darkTheme);
bool isColoredState(Vpn::ConnectionState state);
QPixmap renderIcon(const QString &resourcePath, int size);
QPixmap buildPixmap(int size, Vpn::ConnectionState state, bool darkTheme);
QIcon buildIcon(Vpn::ConnectionState state, bool darkTheme);
QByteArray buildTemplatePng(Vpn::ConnectionState state);
QByteArray buildColorPng(Vpn::ConnectionState state, bool darkTheme);
} // namespace TrayIconCommon
#endif // TRAYICONCOMMON_H
-20
View File
@@ -1,20 +0,0 @@
#include "trayThemeChangeFilter.h"
#include <QEvent>
TrayThemeChangeFilter::TrayThemeChangeFilter(std::function<void()> onThemeChanged, QObject *parent)
: QObject(parent)
, m_onThemeChanged(std::move(onThemeChanged))
{
}
bool TrayThemeChangeFilter::eventFilter(QObject *watched, QEvent *event)
{
Q_UNUSED(watched);
if (event->type() == QEvent::ApplicationPaletteChange || event->type() == QEvent::ThemeChange) {
if (m_onThemeChanged) {
m_onThemeChanged();
}
}
return QObject::eventFilter(watched, event);
}
-21
View File
@@ -1,21 +0,0 @@
#ifndef TRAYTHEMECHANGEFILTER_H
#define TRAYTHEMECHANGEFILTER_H
#include <functional>
#include <QObject>
class TrayThemeChangeFilter final : public QObject {
Q_OBJECT
public:
explicit TrayThemeChangeFilter(std::function<void()> onThemeChanged, QObject *parent = nullptr);
protected:
bool eventFilter(QObject *watched, QEvent *event) override;
private:
std::function<void()> m_onThemeChanged;
};
#endif // TRAYTHEMECHANGEFILTER_H
+16 -1
View File
@@ -5,6 +5,7 @@ from conan.errors import ConanInvalidConfiguration
from conan.tools.scm import Git
from conan.internal.model.pkg_type import PackageType
from conan.tools.files import chdir
from conan.tools.apple import XCRun
import os
import shutil
@@ -49,7 +50,10 @@ class OpenVPNAdapter(ConanFile):
def build(self):
with chdir(self, self.source_folder):
self.run("xcrun xcodebuild"
xcrun = XCRun(self)
xcodebuild = xcrun.find("xcodebuild")
self.run(f"{xcodebuild}"
" -project OpenVPNAdapter.xcodeproj"
" -scheme OpenVPNAdapter"
" -configuration Release"
@@ -57,10 +61,20 @@ class OpenVPNAdapter(ConanFile):
f" -sdk {self._sdk}"
f' "CONFIGURATION_BUILD_DIR={self.build_folder}"'
f' "BUILT_PRODUCTS_DIR={self.build_folder}"'
" MACH_O_TYPE=staticlib"
" BUILD_LIBRARY_FOR_DISTRIBUTION=YES"
" CODE_SIGNING_ALLOWED=NO"
)
openvpnadapter = os.path.join(self.build_folder, "OpenVPNAdapter.framework", "OpenVPNAdapter")
self.run(f"{xcrun.libtool} -static -o"
f" {openvpnadapter}"
f" {openvpnadapter}"
f' {os.path.join(self.build_folder, "OpenVPNClient.framework", "OpenVPNClient")}'
f' {os.path.join(self.build_folder, "LZ4.framework", "LZ4")}'
f' {os.path.join(self.build_folder, "mbedTLS.framework", "mbedTLS")}'
)
def package(self):
shutil.copytree(os.path.join(self.build_folder, "OpenVPNAdapter.framework"),
os.path.join(self.package_folder, "OpenVPNAdapter.framework"))
@@ -70,3 +84,4 @@ class OpenVPNAdapter(ConanFile):
self.cpp_info.type = PackageType.STATIC
self.cpp_info.package_framework = True
self.cpp_info.location = os.path.join(self.package_folder, "OpenVPNAdapter.framework")
self.cpp_info.frameworks = ["SystemConfiguration"]