Compare commits

...
Author SHA1 Message Date
NickVs2015 02838a94d5 fix: add new dep to test (#3301) 2026-10-20 10:22:09 +08:00
NickVs2015 9a1200d6f3 fix: build libagw with go 1.27.1 (#3303) 2026-10-20 10:21:53 +08:00
NickVs2015andvkamn ddde43635e feat: local proxy mode (#3166)
* fix: share double-stop guard via VpnProtocol base class

* feat: add local proxy core module

* feat: local proxy settings api

* feat: wire local proxy into app controllers

* feat: local proxy settings ui

* feat: arbitrate shared xray engine ownership via ipc tokens

* fix: remove connection type

* chore: add qthttpserver to desktop ci qt modules

* fix: local proxy port fallback and active port reporting

* fix: keep text field button aligned when error is shown

* fix: hide local proxy for free servers and guard device unlink

* fix: show local proxy state per server

* fix: anchor text field button to content

* fix: adapt local proxy pages to design

* fix: copy logic and port logic

* refactor: move local proxy files to controllers and utils

* refactor: merge local proxy into LocalProxyController

* refactor: reuse gateway config request and keep local proxy state in memory

---------

Co-authored-by: vkamn <vk@amnezia.org>
2026-10-18 21:25:04 +08:00
vkamn ffba1cb2a4 chore: minor ui fixes (#3295)
* fix: sync ds component sizes with updated figma

* fix: hover only on action buttons in list rows, standalone country row
2026-10-17 23:51:22 +08:00
vkamn 30ff3451c7 fix: prepare gateway request (#3291)
* fix: prepare the gateway request once instead of a blocking callback per attempt

* chore: libagw 1.0.8, gateway and failover timeouts 6s, health check 1s
2026-10-16 00:10:29 +08:00
vkamn db951e9928 chore: minor ui fixes (#3290)
* chore: change amnezia hosting description

* fix: ios safe areas and ds component alignment

- extend window into ios safe areas, pass insets to PageController
- use dark interface style and portrait-only orientation on iphone
- drop bottom inset while keyboard is open
- align controls with figma: title-only cards, caption height,
  selectable list items, nav bar spacing, chip hover, switch rows

* fix: news settings icon unread badge

* fix: align ds effects with figma

- three-layer selection glow for switch, radio and connect ring
- connect button disk with glow in all states
- snackbar elevate shadow spread, dropdown panel shadow
- backdrop blur for loading overlay container
- pressed state layer 0.1 for icon buttons, segments, list items, cards

* refactor: remove Qt5Compat.GraphicalEffects
2026-10-15 23:50:51 +08:00
99 changed files with 2132 additions and 280 deletions

No files matched your search

+8 -8
View File
@@ -88,7 +88,7 @@ jobs:
host: 'linux'
target: 'desktop'
arch: 'linux_gcc_64'
modules: 'qtremoteobjects qt5compat qtshadertools'
modules: 'qtremoteobjects qt5compat qtshadertools qthttpserver qtwebsockets'
dir: ${{ runner.temp }}
setup-python: 'true'
tools: 'tools_ifw'
@@ -209,7 +209,7 @@ jobs:
host: 'windows'
target: 'desktop'
arch: 'win64_msvc2022_64'
modules: 'qtremoteobjects qt5compat qtshadertools'
modules: 'qtremoteobjects qt5compat qtshadertools qthttpserver qtwebsockets'
dir: ${{ runner.temp }}
setup-python: 'true'
tools: 'tools_ifw'
@@ -528,7 +528,7 @@ jobs:
host: 'mac'
target: 'desktop'
arch: 'clang_64'
modules: 'qtremoteobjects qt5compat qtshadertools'
modules: 'qtremoteobjects qt5compat qtshadertools qthttpserver qtwebsockets'
dir: ${{ runner.temp }}
setup-python: 'true'
set-env: 'true'
@@ -671,7 +671,7 @@ jobs:
version: ${{ env.QT_VERSION }}
host: 'mac'
target: 'desktop'
modules: 'qtremoteobjects qt5compat qtshadertools qtmultimedia'
modules: 'qtremoteobjects qt5compat qtshadertools qtmultimedia qthttpserver qtwebsockets'
arch: 'clang_64'
dir: ${{ runner.temp }}
set-env: 'true'
@@ -1105,7 +1105,7 @@ jobs:
host: linux
target: desktop
arch: linux_gcc_64
modules: qtremoteobjects qt5compat qtshadertools
modules: qtremoteobjects qt5compat qtshadertools qthttpserver qtwebsockets
dir: ${{ runner.temp }}
set-env: true
aqtversion: '==3.3.0'
@@ -1181,7 +1181,7 @@ jobs:
host: linux
target: desktop
arch: linux_gcc_64
modules: qtremoteobjects qt5compat qtshadertools
modules: qtremoteobjects qt5compat qtshadertools qthttpserver qtwebsockets
dir: ${{ runner.temp }}
set-env: true
aqtversion: '==3.3.0'
@@ -1303,7 +1303,7 @@ jobs:
host: windows
target: desktop
arch: win64_msvc2022_64
modules: qtremoteobjects qt5compat qtshadertools
modules: qtremoteobjects qt5compat qtshadertools qthttpserver qtwebsockets
dir: ${{ runner.temp }}
set-env: true
@@ -1413,7 +1413,7 @@ jobs:
host: mac
target: desktop
arch: clang_64
modules: qtremoteobjects qt5compat qtshadertools
modules: qtremoteobjects qt5compat qtshadertools qthttpserver qtwebsockets
dir: ${{ runner.temp }}
set-env: true
+2 -2
View File
@@ -37,7 +37,7 @@ add_definitions(-DFREE_V2_ENDPOINT="$ENV{FREE_V2_ENDPOINT}")
add_definitions(-DPREM_V1_ENDPOINT="$ENV{PREM_V1_ENDPOINT}")
if(WIN32 OR (APPLE AND NOT IOS) OR (LINUX AND NOT ANDROID))
set(PACKAGES ${PACKAGES} Widgets)
set(PACKAGES ${PACKAGES} Widgets HttpServer)
endif()
find_package(Qt6 REQUIRED COMPONENTS ${PACKAGES})
@@ -60,7 +60,7 @@ if(TARGET Qt6::CorePrivate)
endif()
if(WIN32 OR (APPLE AND NOT IOS) OR (LINUX AND NOT ANDROID))
set(LIBS ${LIBS} Qt6::Widgets)
set(LIBS ${LIBS} Qt6::Widgets Qt6::HttpServer)
endif()
qt_standard_project_setup()
+5
View File
@@ -129,6 +129,11 @@ void AmneziaApplication::init()
win->setPersistentSceneGraph(true);
win->setPersistentGraphics(true);
#endif
#ifdef Q_OS_IOS
auto pageController = m_coreController->pageController();
pageController->setSafeAreaMargins(win->safeAreaMargins());
QObject::connect(win, &QWindow::safeAreaMarginsChanged, pageController, &PageController::setSafeAreaMargins);
#endif
#if defined(Q_OS_ANDROID) || defined(Q_OS_IOS)
win->show();
#else
+7
View File
@@ -44,6 +44,7 @@ set(HEADERS ${HEADERS}
${CLIENT_ROOT_DIR}/core/controllers/selfhosted/exportController.h
${CLIENT_ROOT_DIR}/core/controllers/connectionController.h
${CLIENT_ROOT_DIR}/core/controllers/settingsController.h
${CLIENT_ROOT_DIR}/core/controllers/localProxyController.h
${CLIENT_ROOT_DIR}/core/controllers/logsController.h
${CLIENT_ROOT_DIR}/core/controllers/api/servicesCatalogController.h
${CLIENT_ROOT_DIR}/core/controllers/api/storePurchaseController.h
@@ -69,6 +70,9 @@ set(HEADERS ${HEADERS}
${CLIENT_ROOT_DIR}/core/utils/api/apiUtils.h
${CLIENT_ROOT_DIR}/core/utils/api/countryCatalog.h
${CLIENT_ROOT_DIR}/core/utils/api/gatewayPayloadBuilder.h
${CLIENT_ROOT_DIR}/core/utils/localProxy/localProxyConstants.h
${CLIENT_ROOT_DIR}/core/utils/localProxy/portUtils.h
${CLIENT_ROOT_DIR}/core/utils/localProxy/xrayConfigUtils.h
${CLIENT_ROOT_DIR}/core/utils/osSignalHandler.h
${CLIENT_ROOT_DIR}/core/utils/swiftBridge.h
${CLIENT_ROOT_DIR}/core/utils/utilities.h
@@ -130,6 +134,7 @@ set(SOURCES ${SOURCES}
${CLIENT_ROOT_DIR}/core/controllers/selfhosted/exportController.cpp
${CLIENT_ROOT_DIR}/core/controllers/connectionController.cpp
${CLIENT_ROOT_DIR}/core/controllers/settingsController.cpp
${CLIENT_ROOT_DIR}/core/controllers/localProxyController.cpp
${CLIENT_ROOT_DIR}/core/controllers/logsController.cpp
${CLIENT_ROOT_DIR}/core/controllers/api/servicesCatalogController.cpp
${CLIENT_ROOT_DIR}/core/controllers/api/storePurchaseController.cpp
@@ -157,6 +162,8 @@ set(SOURCES ${SOURCES}
${CLIENT_ROOT_DIR}/core/utils/api/apiUtils.cpp
${CLIENT_ROOT_DIR}/core/utils/api/countryCatalog.cpp
${CLIENT_ROOT_DIR}/core/utils/api/gatewayPayloadBuilder.cpp
${CLIENT_ROOT_DIR}/core/utils/localProxy/portUtils.cpp
${CLIENT_ROOT_DIR}/core/utils/localProxy/xrayConfigUtils.cpp
${CLIENT_ROOT_DIR}/core/utils/serverConfigUtils.cpp
${CLIENT_ROOT_DIR}/core/utils/osSignalHandler.cpp
${CLIENT_ROOT_DIR}/core/utils/utilities.cpp
@@ -362,6 +362,33 @@ ErrorCode SubscriptionController::updateServiceFromGateway(const QString &server
return applyUpdatedServiceConfig(serverId, serviceProtocol, protocolData, responseBody);
}
ErrorCode SubscriptionController::fetchServiceConfig(const QString &serverId, const QString &serviceProtocol,
QJsonObject &serverConfigJson)
{
auto apiV2 = m_serversRepository->apiV2Config(serverId);
if (!apiV2.has_value()) {
return ErrorCode::InternalError;
}
ProtocolData protocolData = generateProtocolData(serviceProtocol);
QJsonObject apiPayload = GatewayPayloadBuilder(m_appSettingsRepository)
.addField(apiDefs::key::userCountryCode, apiV2->apiConfig.userCountryCode)
.addField(apiDefs::key::serviceType, apiV2->serviceType())
.addField(apiDefs::key::serviceProtocol, serviceProtocol)
.addField(apiDefs::key::publicKey, publicKeyForProtocol(serviceProtocol, protocolData))
.addField(apiDefs::key::authData, apiV2->authData.toJson())
.build();
QByteArray responseBody;
ErrorCode errorCode = executeRequest(QString("%1v1/config"), apiPayload, responseBody, apiV2->apiConfig.isTestPurchase);
if (errorCode != ErrorCode::NoError) {
return errorCode;
}
return extractServerConfigJsonFromResponse(responseBody, serviceProtocol, protocolData, serverConfigJson);
}
void SubscriptionController::markSubscriptionExpiredByServer(const QString &serverId, const ApiV2ServerConfig &apiV2)
{
ApiV2ServerConfig expiredApiV2 = apiV2;
@@ -45,6 +45,8 @@ public:
ErrorCode importTrialFromGateway(const QString &userCountryCode, const QString &serviceType,
const QString &serviceProtocol, const QString &email);
ErrorCode fetchServiceConfig(const QString &serverId, const QString &serviceProtocol, QJsonObject &serverConfigJson);
ErrorCode updateServiceFromGateway(const QString &serverId, const QString &newCountryCode, bool isConnectEvent,
CaptchaInfo *captchaInfoOut = nullptr, ProtocolData *usedProtocolDataOut = nullptr);
@@ -179,6 +179,7 @@ void CoreController::initCoreControllers()
m_importCoreController = new ImportController(m_serversRepository, m_appSettingsRepository, this);
m_connectionController = new ConnectionController(m_serversRepository, m_appSettingsRepository, m_vpnConnection.get(), this);
m_settingsController = new SettingsController(m_serversRepository, m_appSettingsRepository, this);
m_localProxyController = new LocalProxyController(m_serversRepository, m_appSettingsRepository, m_subscriptionController, this);
}
void CoreController::initControllers()
@@ -212,6 +213,9 @@ void CoreController::initControllers()
m_settingsUiController = new SettingsUiController(m_settingsController, m_serversController, this);
setQmlContextProperty("SettingsController", m_settingsUiController);
m_localProxyUiController = new LocalProxyUiController(m_localProxyController, this);
setQmlContextProperty("LocalProxyController", m_localProxyUiController);
m_logsUiController = new LogsUiController(m_settingsController, this);
setQmlContextProperty("LogsController", m_logsUiController);
+4
View File
@@ -24,6 +24,7 @@
#include "ui/controllers/selfhosted/installUiController.h"
#include "ui/controllers/qml/pageController.h"
#include "ui/controllers/settingsUiController.h"
#include "ui/controllers/localProxyUiController.h"
#include "ui/controllers/logsUiController.h"
#include "ui/controllers/serversUiController.h"
#include "ui/controllers/ipSplitTunnelingUiController.h"
@@ -44,6 +45,7 @@
#include "core/controllers/api/newsController.h"
#include "core/controllers/selfhosted/installController.h"
#include "core/controllers/settingsController.h"
#include "core/controllers/localProxyController.h"
#include "core/controllers/connectionController.h"
#include "core/controllers/updateController.h"
@@ -175,6 +177,7 @@ private:
ImportController* m_importCoreController;
ExportUiController* m_exportUiController;
SettingsUiController* m_settingsUiController;
LocalProxyUiController* m_localProxyUiController;
LogsUiController* m_logsUiController;
ServersUiController* m_serversUiController;
IpSplitTunnelingUiController* m_ipSplitTunnelingUiController;
@@ -204,6 +207,7 @@ private:
ExportController* m_exportController;
ConnectionController* m_connectionController;
SettingsController* m_settingsController;
LocalProxyController* m_localProxyController;
ContainersModel* m_containersModel;
ContainersModel* m_defaultServerContainersModel;
@@ -1,5 +1,6 @@
#include "coreSignalHandlers.h"
#include <QCoreApplication>
#include <QTimer>
#include <QtConcurrent>
@@ -32,6 +33,7 @@
#include "core/controllers/selfhosted/installController.h"
#include "core/controllers/selfhosted/exportController.h"
#include "core/controllers/connectionController.h"
#include "core/controllers/localProxyController.h"
#include "ui/models/clientManagementModel.h"
#include "ui/controllers/api/apiNewsUiController.h"
#include "ui/models/containersModel.h"
@@ -88,6 +90,7 @@ void CoreSignalHandlers::initAllHandlers()
initIosSettingsHandler();
initNotificationHandler();
initUpdateFoundHandler();
initLocalProxyHandler();
}
void CoreSignalHandlers::initErrorMessagesHandler()
@@ -494,3 +497,12 @@ void CoreSignalHandlers::initUpdateFoundHandler()
});
}
void CoreSignalHandlers::initLocalProxyHandler()
{
connect(m_coreController->m_connectionController, &ConnectionController::openConnectionRequested, m_coreController->m_localProxyController,
&LocalProxyController::onVpnConnectionRequested);
connect(m_coreController->m_localProxyController, &LocalProxyController::stoppedByVpn, m_coreController->m_pageController,
&PageController::showNotificationMessage);
connect(QCoreApplication::instance(), &QCoreApplication::aboutToQuit, m_coreController->m_localProxyController,
&LocalProxyController::disable);
}
@@ -43,6 +43,7 @@ private:
void initIosSettingsHandler();
void initNotificationHandler();
void initUpdateFoundHandler();
void initLocalProxyHandler();
CoreController* m_coreController;
};
+52 -31
View File
@@ -5,11 +5,13 @@
#include <QFutureWatcher>
#include <QJsonArray>
#include <QJsonDocument>
#include <QMetaObject>
#include <QJsonObject>
#include <QThread>
#include <QUrl>
#include <QtConcurrent/QtConcurrentRun>
#include "core/repositories/secureAppSettingsRepository.h"
#include "core/utils/constants/apiConstants.h"
#include "core/utils/constants/apiKeys.h"
#include "core/utils/api/apiUtils.h"
@@ -32,6 +34,9 @@ namespace
constexpr QLatin1String s3FallbackEndpoints("s3_fallback_endpoints");
constexpr QLatin1String isDevEnvironment("is_dev_environment");
constexpr QLatin1String requestTimeoutMsecs("request_timeout_msecs");
constexpr QLatin1String proxyRequestTimeoutMsecs("proxy_request_timeout_msecs");
constexpr QLatin1String proxyStorageTimeoutMsecs("proxy_storage_timeout_msecs");
constexpr QLatin1String proxyHealthTimeoutMsecs("proxy_health_timeout_msecs");
}
namespace agwOptionsKey
@@ -40,6 +45,11 @@ namespace
constexpr QLatin1String userCountryCode("user_country_code");
}
namespace agwStateKey
{
constexpr QLatin1String workingProxy("working_proxy");
}
constexpr QLatin1String agwStateCacheKey("agw_state");
constexpr QLatin1String agwTracePrefix("agw trace:");
constexpr QLatin1String agwTraceFailoverMarker("suspicious");
@@ -71,6 +81,7 @@ GatewayController::GatewayController(const QString &gatewayEndpoint, const bool
const bool isStrictKillSwitchEnabled, SecureAppSettingsRepository *appSettingsRepository,
QObject *parent)
: QObject(parent),
m_gatewayEndpoint(gatewayEndpoint),
m_isStrictKillSwitchEnabled(isStrictKillSwitchEnabled),
m_appSettingsRepository(appSettingsRepository)
{
@@ -93,13 +104,11 @@ GatewayController::GatewayController(const QString &gatewayEndpoint, const bool
config[agwConfigKey::s3FallbackEndpoints] = QJsonArray::fromStringList(fallbackEndpoints);
config[agwConfigKey::isDevEnvironment] = isDevEnvironment;
config[agwConfigKey::requestTimeoutMsecs] = requestTimeoutMsecs;
config[agwConfigKey::proxyRequestTimeoutMsecs] = apiDefs::proxyRequestTimeoutMsecs;
config[agwConfigKey::proxyStorageTimeoutMsecs] = apiDefs::proxyStorageTimeoutMsecs;
config[agwConfigKey::proxyHealthTimeoutMsecs] = apiDefs::proxyHealthTimeoutMsecs;
agw_callbacks callbacks {};
callbacks.struct_size = sizeof(agw_callbacks);
callbacks.on_before_request = &GatewayController::onBeforeRequest;
callbacks.on_before_request_user_data = this;
m_client = agw_client_create(QJsonDocument(config).toJson(QJsonDocument::Compact).constData(), &callbacks);
m_client = agw_client_create(QJsonDocument(config).toJson(QJsonDocument::Compact).constData(), nullptr);
if (m_client == 0) {
qCritical() << "GatewayController: failed to create gateway client (missing key or endpoint?)";
return;
@@ -137,6 +146,7 @@ amnezia::ErrorCode GatewayController::post(const QString &endpoint, const QJsonO
QFuture<QPair<amnezia::ErrorCode, QByteArray>> GatewayController::postAsync(const QString &endpoint, const QJsonObject apiPayload)
{
prepareRequest();
return QtConcurrent::run(
[this, endpoint, apiPayload]() -> QPair<amnezia::ErrorCode, QByteArray> { return executePost(endpoint, apiPayload); });
}
@@ -190,44 +200,55 @@ amnezia::ErrorCode GatewayController::mapResultCode(const int code, const QByteA
}
}
void GatewayController::onBeforeRequest(const char *host, void *userData)
{
auto *controller = static_cast<GatewayController *>(userData);
const QString hostString = QString::fromUtf8(host);
if (QThread::currentThread() == controller->thread()) {
controller->handleBeforeRequest(hostString);
} else {
QMetaObject::invokeMethod(
controller, [controller, hostString]() { controller->handleBeforeRequest(hostString); },
Qt::BlockingQueuedConnection);
}
}
void GatewayController::handleBeforeRequest(const QString &host)
void GatewayController::prepareRequest()
{
#ifdef Q_OS_IOS
Q_UNUSED(host);
IosController::Instance()->requestInetAccess();
QThread::msleep(10);
#endif
#ifdef AMNEZIA_DESKTOP
if (m_isStrictKillSwitchEnabled) {
if (!m_isStrictKillSwitchEnabled) {
return;
}
QStringList ips;
for (const QString &host : requestHosts()) {
const QString ip = NetworkUtilities::getIPAddress(host);
if (!ip.isEmpty()) {
IpcClient::withInterface([&](QSharedPointer<IpcInterfaceReplica> iface) {
QRemoteObjectPendingReply<bool> reply = iface->addKillSwitchAllowedRange(QStringList { ip });
if (!reply.waitForFinished(1000) || !reply.returnValue()) {
qWarning() << "GatewayController::handleBeforeRequest(): failed to add killswitch exception for" << host;
}
});
ips.append(ip);
}
}
#else
Q_UNUSED(host);
if (ips.isEmpty()) {
return;
}
IpcClient::withInterface([&](QSharedPointer<IpcInterfaceReplica> iface) {
QRemoteObjectPendingReply<bool> reply = iface->addKillSwitchAllowedRange(ips);
if (!reply.waitForFinished(1000) || !reply.returnValue()) {
qWarning() << "GatewayController::prepareRequest(): Failed to execute remote addKillSwitchAllowedRange call";
}
});
#endif
}
QStringList GatewayController::requestHosts() const
{
QStringList hosts;
if (m_client != 0) {
char *state = agw_export_state(m_client);
if (state != nullptr) {
const QString workingProxy = QJsonDocument::fromJson(QByteArray(state)).object().value(agwStateKey::workingProxy).toString();
agw_string_free(state);
if (!workingProxy.isEmpty()) {
hosts.append(QUrl(workingProxy).host());
}
}
}
hosts.append(QUrl(m_gatewayEndpoint).host());
hosts.removeAll(QString());
hosts.removeDuplicates();
return hosts;
}
void GatewayController::persistState()
{
if (m_client == 0 || m_appSettingsRepository == nullptr) {
+4 -2
View File
@@ -7,6 +7,7 @@
#include <QObject>
#include <QPair>
#include <QString>
#include <QStringList>
#include "core/utils/errorCodes.h"
@@ -28,13 +29,14 @@ public:
QFuture<QPair<amnezia::ErrorCode, QByteArray>> postAsync(const QString &endpoint, const QJsonObject apiPayload);
private:
static void onBeforeRequest(const char *host, void *userData);
void handleBeforeRequest(const QString &host);
void prepareRequest();
QStringList requestHosts() const;
QPair<amnezia::ErrorCode, QByteArray> executePost(const QString &endpoint, const QJsonObject &apiPayload);
static amnezia::ErrorCode mapResultCode(const int code, const QByteArray &responseBody);
void persistState();
QString m_gatewayEndpoint;
bool m_isStrictKillSwitchEnabled = false;
SecureAppSettingsRepository *m_appSettingsRepository = nullptr;
@@ -0,0 +1,525 @@
#include "localProxyController.h"
#include "core/controllers/api/subscriptionController.h"
#include "core/repositories/secureAppSettingsRepository.h"
#include "core/repositories/secureServersRepository.h"
#include "core/utils/api/apiUtils.h"
#include "core/utils/constants/configKeys.h"
#include "core/utils/localProxy/localProxyConstants.h"
#include "core/utils/localProxy/portUtils.h"
#include "core/utils/localProxy/xrayConfigUtils.h"
#include <QDebug>
#include <QJsonDocument>
#include <QJsonParseError>
#ifdef AMNEZIA_DESKTOP
#include "core/utils/ipcClient.h"
#include <QHostAddress>
#include <QHttpServer>
#include <QHttpServerResponse>
#include <QTcpServer>
#endif
using namespace amnezia;
LocalProxyController::LocalProxyController(SecureServersRepository *serversRepository,
SecureAppSettingsRepository *appSettingsRepository,
SubscriptionController *subscriptionController, QObject *parent)
: QObject(parent),
m_serversRepository(serversRepository),
m_appSettingsRepository(appSettingsRepository),
m_subscriptionController(subscriptionController)
{
connect(m_serversRepository, &SecureServersRepository::serverEdited, this, &LocalProxyController::onServerEdited);
connect(m_serversRepository, &SecureServersRepository::serverRemoved, this,
[this](const QString &serverId, int) { onServerRemoved(serverId); });
}
LocalProxyController::~LocalProxyController()
{
stop();
}
bool LocalProxyController::isEnabled() const
{
return m_isEnabled;
}
int LocalProxyController::port() const
{
return m_appSettingsRepository->localProxyPort();
}
QString LocalProxyController::ownerId() const
{
return m_appSettingsRepository->localProxyOwnerId();
}
bool LocalProxyController::isPortUserDefined() const
{
return m_appSettingsRepository->isLocalProxyPortUserDefined();
}
int LocalProxyController::activePort() const
{
return m_activePort;
}
bool LocalProxyController::setPort(int port)
{
if (port < localProxy::proxyPortMin || port > localProxy::proxyPortMax) {
return false;
}
const bool isPortChanged = m_appSettingsRepository->localProxyPort() != static_cast<quint16>(port);
if (isPortChanged) {
m_appSettingsRepository->setLocalProxyPort(static_cast<quint16>(port));
}
m_appSettingsRepository->setLocalProxyPortUserDefined(true);
emit stateChanged();
if (isPortChanged && m_isEnabled) {
start();
}
return true;
}
bool LocalProxyController::isPortBusy(int port) const
{
return !portUtils::isPortAvailable(port);
}
bool LocalProxyController::enable(const QString &ownerId, int port)
{
if (!isSupported() || ownerId.isEmpty() || port < localProxy::proxyPortMin || port > localProxy::proxyPortMax) {
return false;
}
if (m_isEnabled && m_appSettingsRepository->localProxyOwnerId() != ownerId) {
return false;
}
if (!portUtils::isPortAvailable(port) && m_appSettingsRepository->isLocalProxyPortUserDefined()) {
return false;
}
if (m_appSettingsRepository->localProxyPort() != static_cast<quint16>(port)) {
m_appSettingsRepository->setLocalProxyPort(static_cast<quint16>(port));
}
m_appSettingsRepository->setLocalProxyOwnerId(ownerId);
m_isEnabled = true;
emit stateChanged();
start();
return true;
}
void LocalProxyController::disable()
{
if (!m_isEnabled) {
return;
}
qDebug() << "Local proxy is disabled";
m_isEnabled = false;
stop();
emit stateChanged();
}
void LocalProxyController::start()
{
if (!startApi(localProxy::apiPort)) {
disableWithError(tr("Local proxy failed to start. Check if the port is available"));
return;
}
if (!syncXray()) {
disableWithError(tr("Couldn’t start the proxy due to an internal error. Try restarting the app"));
return;
}
qDebug() << "Local proxy is running on 127.0.0.1:" << m_apiPort;
}
void LocalProxyController::onServerEdited(const QString &serverId)
{
if (m_apiPort == 0 || m_appSettingsRepository->localProxyOwnerId() != serverId) {
return;
}
qDebug() << "Owner server edited, restarting Xray";
if (restartXray()) {
m_appliedProxyPort = m_appSettingsRepository->localProxyPort();
} else {
disableWithError(tr("Couldn’t start the proxy due to an internal error. Try restarting the app"));
}
}
void LocalProxyController::onServerRemoved(const QString &serverId)
{
if (m_appSettingsRepository->localProxyOwnerId() != serverId) {
return;
}
m_appSettingsRepository->setLocalProxyOwnerId(QString());
if (m_isEnabled) {
m_isEnabled = false;
stop();
}
emit stateChanged();
}
void LocalProxyController::onVpnConnectionRequested()
{
if (!m_isEnabled) {
return;
}
disable();
emit stoppedByVpn(tr("Local proxy stopped because VPN was turned on"));
}
void LocalProxyController::stop()
{
stopXray();
stopApi();
m_appliedProxyPort = 0;
}
bool LocalProxyController::syncXray()
{
const quint16 proxyPort = m_appSettingsRepository->localProxyPort();
bool synced;
if (!isXrayEngineRunning()) {
synced = startXray();
} else if (m_appliedProxyPort != proxyPort) {
qDebug() << "Proxy port changed from" << m_appliedProxyPort << "to" << proxyPort;
synced = restartXray();
} else {
return true;
}
if (synced) {
m_appliedProxyPort = proxyPort;
}
return synced;
}
bool LocalProxyController::startXray()
{
if (isXrayEngineRunning()) {
return true;
}
const auto config = buildXrayConfig();
if (!config) {
return false;
}
if (!startXrayEngine(config->serializedConfig)) {
return false;
}
qDebug() << "Xray started on port" << config->proxyPort;
setActivePort(config->proxyPort);
return true;
}
bool LocalProxyController::stopXray()
{
if (!stopXrayEngine()) {
return false;
}
setActivePort(0);
return true;
}
bool LocalProxyController::restartXray()
{
qDebug() << "Restarting Xray with updated config";
if (!stopXray()) {
return false;
}
return startXray();
}
void LocalProxyController::disableWithError(const QString &message)
{
qWarning() << message;
m_isEnabled = false;
stop();
emit stateChanged();
emit startFailed(message);
}
void LocalProxyController::setActivePort(int port)
{
if (m_activePort == port) {
return;
}
m_activePort = port;
emit stateChanged();
}
int LocalProxyController::runningProxyPort() const
{
return isXrayEngineRunning() ? m_activePort : 0;
}
std::optional<LocalProxyController::XrayConfig> LocalProxyController::buildXrayConfig() const
{
const QString ownerId = m_appSettingsRepository->localProxyOwnerId();
if (ownerId.isEmpty()) {
qWarning() << "Local proxy owner server id is not configured";
return std::nullopt;
}
const auto ownerServer = m_serversRepository->serverJsonById(ownerId);
if (!ownerServer) {
qWarning() << "Owner server with id" << ownerId << "not found";
return std::nullopt;
}
if (!apiUtils::isPremiumServer(*ownerServer)) {
qWarning() << "Server" << ownerServer->value(configKey::name).toString() << "is not premium, local proxy is unavailable";
return std::nullopt;
}
auto serializedConfig = xrayConfigUtils::extractLastConfig(*ownerServer);
if (!serializedConfig) {
serializedConfig = fetchXrayConfigFromGateway(ownerId);
if (!serializedConfig) {
return std::nullopt;
}
}
QJsonParseError parseError;
const QJsonDocument doc = QJsonDocument::fromJson(serializedConfig->toUtf8(), &parseError);
if (parseError.error != QJsonParseError::NoError || !doc.isObject()) {
qWarning() << "Failed to parse Xray config JSON:" << parseError.errorString();
return std::nullopt;
}
const auto proxyPort = selectProxyPort();
if (!proxyPort) {
return std::nullopt;
}
QJsonObject xrayConfig = doc.object();
if (!xrayConfigUtils::setInboundPort(xrayConfig, *proxyPort)) {
qWarning() << "Failed to override local proxy inbound port, using original config";
return XrayConfig { *serializedConfig, 0 };
}
return XrayConfig { QString::fromUtf8(QJsonDocument(xrayConfig).toJson(QJsonDocument::Compact)), *proxyPort };
}
std::optional<int> LocalProxyController::selectProxyPort() const
{
int port = m_appSettingsRepository->localProxyPort();
if (port < localProxy::proxyPortMin || port > localProxy::proxyPortMax) {
port = localProxy::defaultProxyPort;
}
if (portUtils::waitForPort(port, localProxy::portReleaseWaitMs)) {
return port;
}
if (m_appSettingsRepository->isLocalProxyPortUserDefined()) {
qWarning() << "Local proxy port" << port << "is already in use";
return std::nullopt;
}
std::optional<int> freePort;
if (port != localProxy::defaultProxyPort && portUtils::isPortAvailable(localProxy::defaultProxyPort)) {
freePort = localProxy::defaultProxyPort;
} else {
freePort = portUtils::findFirstAvailablePort(localProxy::defaultProxyPort + 1, localProxy::proxyPortMax);
}
if (!freePort) {
qWarning() << "No available local proxy port in range" << localProxy::defaultProxyPort + 1 << "-"
<< localProxy::proxyPortMax;
return std::nullopt;
}
qDebug() << "Local proxy port" << port << "is busy, using" << *freePort;
return freePort;
}
std::optional<QString> LocalProxyController::fetchXrayConfigFromGateway(const QString &serverId) const
{
QJsonObject serverConfig;
const ErrorCode errorCode = m_subscriptionController->fetchServiceConfig(serverId, configKey::vless, serverConfig);
if (errorCode != ErrorCode::NoError) {
qWarning() << "Gateway request failed with error code" << static_cast<int>(errorCode);
return std::nullopt;
}
const auto serializedConfig = xrayConfigUtils::extractLastConfig(serverConfig);
if (!serializedConfig) {
qWarning() << "Gateway response lacks Xray last_config payload";
return std::nullopt;
}
qDebug() << "Fetched Xray config from gateway";
return serializedConfig;
}
#ifdef AMNEZIA_DESKTOP
bool LocalProxyController::isSupported() const
{
return true;
}
bool LocalProxyController::startApi(quint16 port)
{
if (m_httpServer && m_apiPort == port) {
return true;
}
stopApi();
const auto proxyPortValue = [this]() {
const int port = runningProxyPort();
return port > 0 ? QJsonValue(port) : QJsonValue::Null;
};
auto httpServer = new QHttpServer(this);
httpServer->route("/api/v1/up", QHttpServerRequest::Method::Post, [this, proxyPortValue] {
const bool started = startXray();
return QHttpServerResponse(QJsonObject { { "status", started ? "ok" : "error" }, { "proxyPort", proxyPortValue() } });
});
httpServer->route("/api/v1/down", QHttpServerRequest::Method::Post, [this] {
const bool stopped = stopXray();
return QHttpServerResponse(QJsonObject { { "status", stopped ? "ok" : "error" } });
});
httpServer->route("/api/v1/ping", QHttpServerRequest::Method::Get, [proxyPortValue] {
return QHttpServerResponse(QJsonObject { { "status", "ok" }, { "proxyPort", proxyPortValue() } });
});
auto tcpServer = new QTcpServer(httpServer);
if (!tcpServer->listen(QHostAddress::LocalHost, port) || !httpServer->bind(tcpServer)) {
qWarning() << "Failed to start HTTP API server on port" << port;
delete httpServer;
return false;
}
m_httpServer = httpServer;
m_apiPort = port;
qDebug() << "HTTP API server is running on localhost:" << port;
return true;
}
void LocalProxyController::stopApi()
{
delete m_httpServer;
m_httpServer = nullptr;
m_apiPort = 0;
}
bool LocalProxyController::startXrayEngine(const QString &config)
{
if (config.trimmed().isEmpty()) {
qWarning() << "Xray config content is empty";
return false;
}
const qint64 token = IpcClient::withInterface(
[&](QSharedPointer<IpcInterfaceReplica> iface) -> qint64 {
auto xrayStart = iface->xrayStartOwned(config);
if (!xrayStart.waitForFinished()) {
return 0;
}
return xrayStart.returnValue();
},
[]() -> qint64 { return 0; });
if (token == 0) {
qWarning() << "Failed to start Xray via IPC";
return false;
}
m_xrayToken = token;
return true;
}
bool LocalProxyController::stopXrayEngine()
{
if (m_xrayToken == 0) {
return true;
}
const bool stopped = IpcClient::withInterface(
[this](QSharedPointer<IpcInterfaceReplica> iface) {
auto xrayStop = iface->xrayStopOwned(m_xrayToken);
return xrayStop.waitForFinished() && xrayStop.returnValue();
},
[]() { return false; });
if (!stopped) {
qWarning() << "Failed to stop Xray via IPC";
return false;
}
m_xrayToken = 0;
qDebug() << "Xray stopped";
return true;
}
bool LocalProxyController::isXrayEngineRunning() const
{
if (m_xrayToken == 0) {
return false;
}
return IpcClient::withInterface(
[this](QSharedPointer<IpcInterfaceReplica> iface) {
auto currentToken = iface->xrayCurrentToken();
return currentToken.waitForFinished() && currentToken.returnValue() == m_xrayToken;
},
[]() { return false; });
}
#else
bool LocalProxyController::isSupported() const
{
return false;
}
bool LocalProxyController::startApi(quint16)
{
return false;
}
void LocalProxyController::stopApi()
{
}
bool LocalProxyController::startXrayEngine(const QString &)
{
return false;
}
bool LocalProxyController::stopXrayEngine()
{
return true;
}
bool LocalProxyController::isXrayEngineRunning() const
{
return false;
}
#endif
@@ -0,0 +1,84 @@
#ifndef LOCALPROXYCONTROLLER_H
#define LOCALPROXYCONTROLLER_H
#include <optional>
#include <QObject>
#include <QString>
class QHttpServer;
class SecureServersRepository;
class SecureAppSettingsRepository;
class SubscriptionController;
class LocalProxyController : public QObject
{
Q_OBJECT
public:
LocalProxyController(SecureServersRepository *serversRepository, SecureAppSettingsRepository *appSettingsRepository,
SubscriptionController *subscriptionController, QObject *parent = nullptr);
~LocalProxyController();
bool isSupported() const;
bool isEnabled() const;
int port() const;
QString ownerId() const;
bool isPortUserDefined() const;
int activePort() const;
bool setPort(int port);
bool isPortBusy(int port) const;
bool enable(const QString &ownerId, int port);
void disable();
public slots:
void onServerEdited(const QString &serverId);
void onServerRemoved(const QString &serverId);
void onVpnConnectionRequested();
signals:
void stateChanged();
void startFailed(const QString &message);
void stoppedByVpn(const QString &message);
private:
struct XrayConfig
{
QString serializedConfig;
int proxyPort = 0;
};
void start();
void stop();
bool syncXray();
bool startXray();
bool stopXray();
bool restartXray();
void disableWithError(const QString &message);
void setActivePort(int port);
int runningProxyPort() const;
std::optional<XrayConfig> buildXrayConfig() const;
std::optional<int> selectProxyPort() const;
std::optional<QString> fetchXrayConfigFromGateway(const QString &serverId) const;
bool startApi(quint16 port);
void stopApi();
bool startXrayEngine(const QString &config);
bool stopXrayEngine();
bool isXrayEngineRunning() const;
SecureServersRepository *m_serversRepository;
SecureAppSettingsRepository *m_appSettingsRepository;
SubscriptionController *m_subscriptionController;
bool m_isEnabled = false;
QHttpServer *m_httpServer = nullptr;
quint16 m_apiPort = 0;
qint64 m_xrayToken = 0;
quint16 m_appliedProxyPort = 0;
int m_activePort = 0;
};
#endif // LOCALPROXYCONTROLLER_H
+2 -1
View File
@@ -13,6 +13,7 @@
#include "core/controllers/gatewayController.h"
#include "core/utils/api/gatewayPayloadBuilder.h"
#include "core/utils/appUiConfig.h"
#include "core/utils/constants/apiConstants.h"
#include "core/utils/constants/apiKeys.h"
#include "core/utils/selfhosted/scriptsRegistry.h"
@@ -140,7 +141,7 @@ void UpdateController::checkForUpdates()
auto gatewayController = QSharedPointer<GatewayController>::create(m_appSettingsRepository->getGatewayEndpoint(),
m_appSettingsRepository->isDevGatewayEnv(),
7000,
apiDefs::requestTimeoutMsecs,
m_appSettingsRepository->isStrictKillSwitchEnabled(),
m_appSettingsRepository);
@@ -61,6 +61,10 @@ void OpenVpnProtocol::cleanupResources()
void OpenVpnProtocol::stop()
{
if (guardStop()) {
return;
}
qDebug() << "OpenVpnProtocol::stop()";
const bool wasActive = m_connectionState == Vpn::ConnectionState::Preparing
@@ -179,6 +183,8 @@ void OpenVpnProtocol::updateRouteGateway(QString line)
ErrorCode OpenVpnProtocol::start()
{
resetStopGuard();
cleanupResources();
if (!QFileInfo::exists(configPath())) {
+14
View File
@@ -27,6 +27,20 @@ VpnProtocol::VpnProtocol(const QJsonObject &configuration, QObject *parent)
connect(m_timeoutTimer, &QTimer::timeout, this, &VpnProtocol::onTimeout);
}
bool VpnProtocol::guardStop()
{
if (m_stopped) {
return true;
}
m_stopped = true;
return false;
}
void VpnProtocol::resetStopGuard()
{
m_stopped = false;
}
void VpnProtocol::setLastError(ErrorCode lastError)
{
m_lastError = lastError;
+5
View File
@@ -89,6 +89,11 @@ protected:
void startTimeoutTimer();
void stopTimeoutTimer();
bool guardStop();
void resetStopGuard();
bool m_stopped = false;
Vpn::ConnectionState m_connectionState;
QString m_routeGateway;
+4 -1
View File
@@ -50,8 +50,10 @@ WireguardProtocol::~WireguardProtocol()
void WireguardProtocol::stop()
{
if (guardStop()) {
return;
}
stopMzImpl();
return;
}
ErrorCode WireguardProtocol::startMzImpl()
@@ -75,5 +77,6 @@ ErrorCode WireguardProtocol::stopMzImpl()
ErrorCode WireguardProtocol::start()
{
resetStopGuard();
return startMzImpl();
}
+12 -4
View File
@@ -67,6 +67,8 @@ XrayProtocol::~XrayProtocol()
ErrorCode XrayProtocol::start()
{
resetStopGuard();
qDebug() << "XrayProtocol::start()";
// Inject SOCKS5 auth into the inbound before starting xray.
@@ -92,11 +94,12 @@ ErrorCode XrayProtocol::start()
return IpcClient::withInterface(
[&](QSharedPointer<IpcInterfaceReplica> iface) {
auto xrayStart = iface->xrayStart(xrayConfigStr);
if (!xrayStart.waitForFinished() || !xrayStart.returnValue()) {
auto xrayStart = iface->xrayStartOwned(xrayConfigStr);
if (!xrayStart.waitForFinished() || xrayStart.returnValue() == 0) {
qCritical() << "Failed to start xray";
return ErrorCode::XrayExecutableCrashed;
}
m_xrayToken = xrayStart.returnValue();
return startTun2Socks();
},
[]() { return ErrorCode::AmneziaServiceConnectionFailed; });
@@ -104,9 +107,13 @@ ErrorCode XrayProtocol::start()
void XrayProtocol::stop()
{
if (guardStop()) {
return;
}
qDebug() << "XrayProtocol::stop()";
IpcClient::withInterface([](QSharedPointer<IpcInterfaceReplica> iface) {
IpcClient::withInterface([this](QSharedPointer<IpcInterfaceReplica> iface) {
auto disableKillSwitch = iface->disableKillSwitch();
if (!disableKillSwitch.waitForFinished() || !disableKillSwitch.returnValue())
qWarning() << "Failed to disable killswitch";
@@ -123,9 +130,10 @@ void XrayProtocol::stop()
if (!deleteTun.waitForFinished() || !deleteTun.returnValue())
qWarning() << "Failed to delete tun";
auto xrayStop = iface->xrayStop();
auto xrayStop = iface->xrayStopOwned(m_xrayToken);
if (!xrayStop.waitForFinished() || !xrayStop.returnValue())
qWarning() << "Failed to stop xray";
m_xrayToken = 0;
});
if (m_tun2socksProcess) {
+4
View File
@@ -38,6 +38,10 @@ private:
int m_tun2socksRetryCount = 0;
static constexpr int maxTun2SocksRetries = 5;
static constexpr int tun2socksRetryDelayMs = 400;
// Owner token of the shared xray engine; a late stop with a stale token
// won't kill an engine restarted by another consumer (e.g. the local proxy).
qint64 m_xrayToken = 0;
};
#endif // XRAYPROTOCOL_H
@@ -504,3 +504,33 @@ void SecureAppSettingsRepository::setXraySavedConfigs(const QByteArray &data)
{
setValue("Xray/savedConfigs", data);
}
QString SecureAppSettingsRepository::localProxyOwnerId() const
{
return value("Conf/localProxyOwnerId", "").toString();
}
void SecureAppSettingsRepository::setLocalProxyOwnerId(const QString &serverId)
{
setValue("Conf/localProxyOwnerId", serverId);
}
quint16 SecureAppSettingsRepository::localProxyPort() const
{
return static_cast<quint16>(value("Conf/localProxyPort", 10808).toUInt());
}
void SecureAppSettingsRepository::setLocalProxyPort(quint16 port)
{
setValue("Conf/localProxyPort", port);
}
bool SecureAppSettingsRepository::isLocalProxyPortUserDefined() const
{
return value("Conf/localProxyPortUserDefined", false).toBool();
}
void SecureAppSettingsRepository::setLocalProxyPortUserDefined(bool userDefined)
{
setValue("Conf/localProxyPortUserDefined", userDefined);
}
@@ -105,6 +105,13 @@ public:
QByteArray xraySavedConfigs() const;
void setXraySavedConfigs(const QByteArray &data);
QString localProxyOwnerId() const;
void setLocalProxyOwnerId(const QString &serverId);
quint16 localProxyPort() const;
void setLocalProxyPort(quint16 port);
bool isLocalProxyPortUserDefined() const;
void setLocalProxyPortUserDefined(bool userDefined);
signals:
void appLanguageChanged(QLocale locale);
void allowedDnsServersChanged(const QStringList &servers);
@@ -323,6 +323,15 @@ serverConfigUtils::ConfigType SecureServersRepository::serverKind(const QString
return serverConfigUtils::configTypeFromJson(withoutStorageServerId(it.value()));
}
std::optional<QJsonObject> SecureServersRepository::serverJsonById(const QString &serverId) const
{
const auto it = m_serverJsonById.constFind(serverId);
if (it == m_serverJsonById.constEnd()) {
return std::nullopt;
}
return it.value();
}
std::optional<SelfHostedAdminServerConfig> SecureServersRepository::selfHostedAdminConfig(const QString &serverId) const
{
const auto it = m_serverJsonById.constFind(serverId);
@@ -31,6 +31,8 @@ public:
void removeServer(const QString &serverId);
serverConfigUtils::ConfigType serverKind(const QString &serverId) const;
std::optional<QJsonObject> serverJsonById(const QString &serverId) const;
std::optional<SelfHostedAdminServerConfig> selfHostedAdminConfig(const QString &serverId) const;
std::optional<SelfHostedUserServerConfig> selfHostedUserConfig(const QString &serverId) const;
std::optional<NativeServerConfig> nativeConfig(const QString &serverId) const;
+4 -1
View File
@@ -4,7 +4,10 @@
namespace apiDefs
{
constexpr int requestTimeoutMsecs = 12 * 1000; // 12 secs
constexpr int requestTimeoutMsecs = 6 * 1000;
constexpr int proxyRequestTimeoutMsecs = 6 * 1000;
constexpr int proxyStorageTimeoutMsecs = 6 * 1000;
constexpr int proxyHealthTimeoutMsecs = 1000;
} // namespace apiDefs
@@ -0,0 +1,15 @@
#ifndef LOCALPROXYDEFS_H
#define LOCALPROXYDEFS_H
#include <QtGlobal>
namespace amnezia::localProxy
{
constexpr int defaultProxyPort = 10808;
constexpr int proxyPortMin = 1024;
constexpr int proxyPortMax = 65535;
constexpr quint16 apiPort = 49490;
constexpr int portReleaseWaitMs = 800;
}
#endif // LOCALPROXYDEFS_H
@@ -0,0 +1,51 @@
#include "portUtils.h"
#include "localProxyConstants.h"
#include <QElapsedTimer>
#include <QHostAddress>
#include <QTcpServer>
#include <QThread>
using namespace amnezia;
bool portUtils::isPortAvailable(int port)
{
if (port < localProxy::proxyPortMin || port > localProxy::proxyPortMax) {
return false;
}
QTcpServer server;
const bool success = server.listen(QHostAddress::LocalHost, static_cast<quint16>(port));
server.close();
return success;
}
bool portUtils::waitForPort(int port, int timeoutMs)
{
QElapsedTimer timer;
timer.start();
while (!isPortAvailable(port)) {
if (timer.elapsed() >= timeoutMs) {
return false;
}
QThread::msleep(200);
}
return true;
}
std::optional<int> portUtils::findFirstAvailablePort(int startPort, int endPort)
{
startPort = qMax(startPort, localProxy::proxyPortMin);
endPort = qMin(endPort, localProxy::proxyPortMax);
for (int port = startPort; port <= endPort; ++port) {
if (isPortAvailable(port)) {
return port;
}
}
return std::nullopt;
}
+13
View File
@@ -0,0 +1,13 @@
#ifndef PORTUTILS_H
#define PORTUTILS_H
#include <optional>
namespace portUtils
{
bool isPortAvailable(int port);
bool waitForPort(int port, int timeoutMs);
std::optional<int> findFirstAvailablePort(int startPort, int endPort);
}
#endif // PORTUTILS_H
@@ -0,0 +1,47 @@
#include "xrayConfigUtils.h"
#include "core/utils/constants/configKeys.h"
#include "core/utils/containers/containerUtils.h"
#include <QJsonArray>
using namespace amnezia;
std::optional<QString> xrayConfigUtils::extractLastConfig(const QJsonObject &serverConfig)
{
const QJsonArray containers = serverConfig.value(configKey::containers).toArray();
const QString targetContainer = ContainerUtils::containerToString(DockerContainer::Xray);
for (const QJsonValue &value : containers) {
const QJsonObject container = value.toObject();
if (container.value(configKey::container).toString() != targetContainer) {
continue;
}
const QJsonObject proto = container.value(QString(configKey::xray)).toObject();
const QString serialized = proto.value(configKey::lastConfig).toString();
if (!serialized.isEmpty()) {
return serialized;
}
}
return std::nullopt;
}
bool xrayConfigUtils::setInboundPort(QJsonObject &xrayConfig, int port)
{
if (!xrayConfig.value(QLatin1String("inbounds")).isArray()) {
return false;
}
QJsonArray inbounds = xrayConfig.value(QLatin1String("inbounds")).toArray();
if (inbounds.isEmpty() || !inbounds.at(0).isObject()) {
return false;
}
QJsonObject firstInbound = inbounds.at(0).toObject();
firstInbound.insert(QLatin1String("port"), port);
inbounds[0] = firstInbound;
xrayConfig.insert(QLatin1String("inbounds"), inbounds);
return true;
}
@@ -0,0 +1,15 @@
#ifndef XRAYCONFIGUTILS_H
#define XRAYCONFIGUTILS_H
#include <optional>
#include <QJsonObject>
#include <QString>
namespace xrayConfigUtils
{
std::optional<QString> extractLastConfig(const QJsonObject &serverConfig);
bool setInboundPort(QJsonObject &xrayConfig, int port);
}
#endif // XRAYCONFIGUTILS_H
-14
View File
@@ -1,14 +0,0 @@
<svg width="24" height="24" viewBox="0 0 74 74" fill="none" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_4_34)">
<path d="M55.5 12.3333H18.5C15.0942 12.3333 12.3333 15.0943 12.3333 18.5V55.5C12.3333 58.9058 15.0942 61.6667 18.5 61.6667H55.5C58.9057 61.6667 61.6666 58.9058 61.6666 55.5V18.5C61.6666 15.0943 58.9057 12.3333 55.5 12.3333Z" stroke="#CBCAC8" stroke-width="5" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M21.5833 24.6667H52.4167" stroke="#CBCAC8" stroke-width="5" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M21.5833 37H52.4167" stroke="#CBCAC8" stroke-width="5" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M21.5833 49.3333H40.0833" stroke="#CBCAC8" stroke-width="5" stroke-linecap="round" stroke-linejoin="round"/>
<circle cx="61.5" cy="12.5" r="15" fill="#FBB36B" stroke="#1C1D21" stroke-width="5"/>
</g>
<defs>
<clipPath id="clip0_4_34">
<rect width="74" height="74" fill="white"/>
</clipPath>
</defs>
</svg>

Before

Width:  |  Height:  |  Size: 982 B

+3 -8
View File
@@ -1,8 +1,3 @@
<svg width="24" height="24" xmlns="http://www.w3.org/2000/svg" fill="none" stroke="#CBCAC8" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round">
<!-- Основа газеты -->
<rect x="4" y="4" width="16" height="16" rx="2"/>
<!-- Линии текста -->
<line x1="7" y1="8" x2="17" y2="8"/>
<line x1="7" y1="12" x2="17" y2="12"/>
<line x1="7" y1="16" x2="13" y2="16"/>
</svg>
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M20 1C20.7957 1 21.5585 1.3163 22.1211 1.87891C22.6837 2.44152 23 3.20435 23 4V20C23 20.7957 22.6837 21.5585 22.1211 22.1211C21.5585 22.6837 20.7957 23 20 23H4C3.9647 23 3.92987 22.9977 3.89551 22.9941C3.13785 22.9677 2.41681 22.659 1.87891 22.1211C1.3163 21.5585 1 20.7957 1 20V11C1 9.34772 2.34772 8 4 8H5V4C5 3.20435 5.3163 2.44152 5.87891 1.87891C6.44152 1.3163 7.20435 1 8 1H20ZM4 10C3.45228 10 3 10.4523 3 11V20C3 20.2652 3.10543 20.5195 3.29297 20.707C3.48051 20.8946 3.73478 21 4 21C4.26522 21 4.51949 20.8946 4.70703 20.707C4.89457 20.5195 5 20.2652 5 20V10H4ZM8 3C7.73478 3 7.4805 3.10543 7.29297 3.29297C7.10543 3.4805 7 3.73478 7 4V20C7 20.3444 6.93703 20.6814 6.82422 21H20C20.2652 21 20.5195 20.8946 20.707 20.707C20.8946 20.5195 21 20.2652 21 20V4C21 3.73478 20.8946 3.48051 20.707 3.29297C20.5195 3.10543 20.2652 3 20 3H8ZM15 17C15.5523 17 16 17.4477 16 18C16 18.5523 15.5523 19 15 19H10C9.44772 19 9 18.5523 9 18C9 17.4477 9.44771 17 10 17H15ZM18 13C18.5523 13 19 13.4477 19 14C19 14.5523 18.5523 15 18 15H10C9.44771 15 9 14.5523 9 14C9 13.4477 9.44771 13 10 13H18ZM18 5C18.5523 5 19 5.44772 19 6V10C19 10.5523 18.5523 11 18 11H10C9.44771 11 9 10.5523 9 10V6C9 5.44772 9.44771 5 10 5H18ZM11 9H17V7H11V9Z" fill="#E4E4E7"/>
</svg>

Before

Width:  |  Height:  |  Size: 410 B

After

Width:  |  Height:  |  Size: 1.3 KiB

-1
View File
@@ -48,7 +48,6 @@
<file>controls/map-pin.svg</file>
<file>controls/more-vertical.svg</file>
<file>controls/news.svg</file>
<file>controls/news-unread.svg</file>
<file>controls/unread-dot.svg</file>
<file>controls/plus.svg</file>
<file>controls/qr-code.svg</file>
+1 -2
View File
@@ -57,7 +57,6 @@
<false/>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationPortrait</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
@@ -68,7 +67,7 @@
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UIUserInterfaceStyle</key>
<string>Light</string>
<string>Dark</string>
<key>com.wireguard.ios.app_group_id</key>
<string>${BUILD_IOS_GROUP_IDENTIFIER}</string>
<key>UIViewControllerBasedStatusBarAppearance</key>
+2 -2
View File
@@ -5289,8 +5289,8 @@ Create one from the current settings.</source>
</message>
<message>
<location filename="../ui/qml/Pages2/PageSetupWizardCredentials.qml" line="133"/>
<source>Amnezia hosting. VPN servers without complicated settings and headaches</source>
<translation>استضافة Amnezia. خوادم VPN بلا إعدادات معقّدة ولا صداع</translation>
<source>Amnezia Hosting - VPN servers without complicated settings</source>
<translation>Amnezia Hosting - خوادم VPN بلا إعدادات معقّدة</translation>
</message>
<message>
<location filename="../ui/qml/Pages2/PageSetupWizardCredentials.qml" line="147"/>
+2 -2
View File
@@ -5276,8 +5276,8 @@ Cree una a partir de los ajustes actuales.</translation>
</message>
<message>
<location filename="../ui/qml/Pages2/PageSetupWizardCredentials.qml" line="133"/>
<source>Amnezia hosting. VPN servers without complicated settings and headaches</source>
<translation>Hosting de Amnezia. Servidores VPN sin ajustes complicados ni quebraderos de cabeza</translation>
<source>Amnezia Hosting - VPN servers without complicated settings</source>
<translation>Amnezia Hosting - servidores VPN sin ajustes complicados</translation>
</message>
<message>
<location filename="../ui/qml/Pages2/PageSetupWizardCredentials.qml" line="147"/>
+2 -2
View File
@@ -5273,8 +5273,8 @@ Create one from the current settings.</source>
</message>
<message>
<location filename="../ui/qml/Pages2/PageSetupWizardCredentials.qml" line="133"/>
<source>Amnezia hosting. VPN servers without complicated settings and headaches</source>
<translation>هاستینگ Amnezia. سرورهای VPN بدون تنظیمات پیچیده و دردسر</translation>
<source>Amnezia Hosting - VPN servers without complicated settings</source>
<translation>Amnezia Hosting - سرورهای VPN بدون تنظیمات پیچیده</translation>
</message>
<message>
<location filename="../ui/qml/Pages2/PageSetupWizardCredentials.qml" line="147"/>
+2 -2
View File
@@ -5276,8 +5276,8 @@ Créez-en une à partir des paramètres actuels.</translation>
</message>
<message>
<location filename="../ui/qml/Pages2/PageSetupWizardCredentials.qml" line="133"/>
<source>Amnezia hosting. VPN servers without complicated settings and headaches</source>
<translation>Hébergement Amnezia. Des serveurs VPN sans réglages compliqués ni prise de tête</translation>
<source>Amnezia Hosting - VPN servers without complicated settings</source>
<translation>Amnezia Hosting - des serveurs VPN sans réglages compliqués</translation>
</message>
<message>
<location filename="../ui/qml/Pages2/PageSetupWizardCredentials.qml" line="147"/>
+2 -2
View File
@@ -5276,8 +5276,8 @@ Create one from the current settings.</source>
</message>
<message>
<location filename="../ui/qml/Pages2/PageSetupWizardCredentials.qml" line="133"/>
<source>Amnezia hosting. VPN servers without complicated settings and headaches</source>
<translation>Amnezia होस्टिंग। जटिल सेटिंग्स और झंझट के बिना VPN सर्वर</translation>
<source>Amnezia Hosting - VPN servers without complicated settings</source>
<translation>Amnezia Hosting - जटिल सेटिंग्स के बिना VPN सर्वर</translation>
</message>
<message>
<location filename="../ui/qml/Pages2/PageSetupWizardCredentials.qml" line="147"/>
+2 -2
View File
@@ -5273,8 +5273,8 @@ Create one from the current settings.</source>
</message>
<message>
<location filename="../ui/qml/Pages2/PageSetupWizardCredentials.qml" line="133"/>
<source>Amnezia hosting. VPN servers without complicated settings and headaches</source>
<translation>Amnezia 호스팅. 복잡한 설정도 번거로움도 없는 VPN 서버</translation>
<source>Amnezia Hosting - VPN servers without complicated settings</source>
<translation>Amnezia Hosting - 복잡한 설정 없는 VPN 서버</translation>
</message>
<message>
<location filename="../ui/qml/Pages2/PageSetupWizardCredentials.qml" line="147"/>
+2 -2
View File
@@ -5273,8 +5273,8 @@ Create one from the current settings.</source>
</message>
<message>
<location filename="../ui/qml/Pages2/PageSetupWizardCredentials.qml" line="133"/>
<source>Amnezia hosting. VPN servers without complicated settings and headaches</source>
<translation>Amnezia hosting။ ရှုပ်ထွေးသော ဆက်တင်များနှင့် ခေါင်းကိုက်စရာများ မလိုသော VPN ဆာဗာများ</translation>
<source>Amnezia Hosting - VPN servers without complicated settings</source>
<translation>Amnezia Hosting - ရှုပ်ထွေးသော ဆက်တင်များ မလိုသော VPN ဆာဗာများ</translation>
</message>
<message>
<location filename="../ui/qml/Pages2/PageSetupWizardCredentials.qml" line="147"/>
+2 -2
View File
@@ -5704,8 +5704,8 @@ Create one from the current settings.</source>
</message>
<message>
<location filename="../ui/qml/Pages2/PageSetupWizardCredentials.qml" line="133"/>
<source>Amnezia hosting. VPN servers without complicated settings and headaches</source>
<translation>Хостинг Amnezia. VPN-серверы без сложных настроек и головной боли</translation>
<source>Amnezia Hosting - VPN servers without complicated settings</source>
<translation>Amnezia Hosting - VPN-серверы без сложных настроек</translation>
</message>
<message>
<location filename="../ui/qml/Pages2/PageSetupWizardCredentials.qml" line="147"/>
+2 -2
View File
@@ -5273,8 +5273,8 @@ Create one from the current settings.</source>
</message>
<message>
<location filename="../ui/qml/Pages2/PageSetupWizardCredentials.qml" line="133"/>
<source>Amnezia hosting. VPN servers without complicated settings and headaches</source>
<translation>Amnezia hosting เซิร์ฟเวอร์ VPN ที่ไม่ต้องตั้งค่ายากและไม่ต้องกังวล</translation>
<source>Amnezia Hosting - VPN servers without complicated settings</source>
<translation>Amnezia Hosting - เซิร์ฟเวอร์ VPN ที่ไม่ต้องตั้งค่ายุ่งยาก</translation>
</message>
<message>
<location filename="../ui/qml/Pages2/PageSetupWizardCredentials.qml" line="147"/>
+2 -2
View File
@@ -5279,8 +5279,8 @@ Create one from the current settings.</source>
</message>
<message>
<location filename="../ui/qml/Pages2/PageSetupWizardCredentials.qml" line="133"/>
<source>Amnezia hosting. VPN servers without complicated settings and headaches</source>
<translation>Хостинг Amnezia. VPN-сервери без складних налаштувань і зайвого клопоту</translation>
<source>Amnezia Hosting - VPN servers without complicated settings</source>
<translation>Amnezia Hosting - VPN-сервери без складних налаштувань</translation>
</message>
<message>
<location filename="../ui/qml/Pages2/PageSetupWizardCredentials.qml" line="147"/>
+2 -2
View File
@@ -5276,8 +5276,8 @@ Create one from the current settings.</source>
</message>
<message>
<location filename="../ui/qml/Pages2/PageSetupWizardCredentials.qml" line="133"/>
<source>Amnezia hosting. VPN servers without complicated settings and headaches</source>
<translation>Amnezia ہوسٹنگ۔ پیچیدہ ترتیبات اور جھنجھٹ کے بغیر VPN سرورز</translation>
<source>Amnezia Hosting - VPN servers without complicated settings</source>
<translation>Amnezia Hosting - پیچیدہ ترتیبات کے بغیر VPN سرورز</translation>
</message>
<message>
<location filename="../ui/qml/Pages2/PageSetupWizardCredentials.qml" line="147"/>
+2 -2
View File
@@ -5273,8 +5273,8 @@ Create one from the current settings.</source>
</message>
<message>
<location filename="../ui/qml/Pages2/PageSetupWizardCredentials.qml" line="133"/>
<source>Amnezia hosting. VPN servers without complicated settings and headaches</source>
<translation>Amnezia 托管服务。无需复杂设置、省心的 VPN 服务器</translation>
<source>Amnezia Hosting - VPN servers without complicated settings</source>
<translation>Amnezia Hosting - 无需复杂设置的 VPN 服务器</translation>
</message>
<message>
<location filename="../ui/qml/Pages2/PageSetupWizardCredentials.qml" line="147"/>
@@ -0,0 +1,58 @@
#include "localProxyUiController.h"
LocalProxyUiController::LocalProxyUiController(LocalProxyController *localProxyController, QObject *parent)
: QObject(parent), m_localProxyController(localProxyController)
{
connect(m_localProxyController, &LocalProxyController::stateChanged, this, &LocalProxyUiController::stateChanged);
connect(m_localProxyController, &LocalProxyController::startFailed, this, &LocalProxyUiController::startFailed);
}
bool LocalProxyUiController::isSupported() const
{
return m_localProxyController->isSupported();
}
bool LocalProxyUiController::isEnabled() const
{
return m_localProxyController->isEnabled();
}
int LocalProxyUiController::port() const
{
return m_localProxyController->port();
}
QString LocalProxyUiController::ownerId() const
{
return m_localProxyController->ownerId();
}
int LocalProxyUiController::activePort() const
{
return m_localProxyController->activePort();
}
bool LocalProxyUiController::isPortUserDefined() const
{
return m_localProxyController->isPortUserDefined();
}
bool LocalProxyUiController::setPort(int port)
{
return m_localProxyController->setPort(port);
}
bool LocalProxyUiController::isPortBusy(int port) const
{
return m_localProxyController->isPortBusy(port);
}
bool LocalProxyUiController::enable(const QString &ownerId, int port)
{
return m_localProxyController->enable(ownerId, port);
}
void LocalProxyUiController::disable()
{
m_localProxyController->disable();
}
@@ -0,0 +1,41 @@
#ifndef LOCALPROXYUICONTROLLER_H
#define LOCALPROXYUICONTROLLER_H
#include <QObject>
#include "core/controllers/localProxyController.h"
class LocalProxyUiController : public QObject
{
Q_OBJECT
public:
explicit LocalProxyUiController(LocalProxyController *localProxyController, QObject *parent = nullptr);
Q_PROPERTY(bool isSupported READ isSupported CONSTANT)
Q_PROPERTY(bool isEnabled READ isEnabled NOTIFY stateChanged)
Q_PROPERTY(int port READ port NOTIFY stateChanged)
Q_PROPERTY(QString ownerId READ ownerId NOTIFY stateChanged)
Q_PROPERTY(int activePort READ activePort NOTIFY stateChanged)
public slots:
bool isSupported() const;
bool isEnabled() const;
int port() const;
QString ownerId() const;
int activePort() const;
bool isPortUserDefined() const;
bool setPort(int port);
bool isPortBusy(int port) const;
bool enable(const QString &ownerId, int port);
void disable();
signals:
void stateChanged();
void startFailed(const QString &message);
private:
LocalProxyController *m_localProxyController;
};
#endif // LOCALPROXYUICONTROLLER_H
+24 -2
View File
@@ -9,6 +9,7 @@
#if defined(Q_OS_ANDROID) || defined(Q_OS_IOS) || defined(MACOS_NE)
#include <QGuiApplication>
#include <QInputMethod>
#else
#include <QApplication>
#endif
@@ -41,6 +42,10 @@ PageController::PageController(ServersController* serversController, SettingsCon
});
#endif
#ifdef Q_OS_IOS
connect(QGuiApplication::inputMethod(), &QInputMethod::visibleChanged, this, &PageController::safeAreaBottomMarginChanged);
#endif
#if defined Q_OS_MACX
connect(this, &PageController::raiseMainWindow, []() {
setDockIconVisible(true);
@@ -191,7 +196,7 @@ int PageController::getSafeAreaTopMargin()
return result;
}
#endif
return 0;
return m_safeAreaMargins.top();
}
int PageController::getSafeAreaBottomMargin()
@@ -207,7 +212,24 @@ int PageController::getSafeAreaBottomMargin()
return result;
}
#endif
return 0;
#ifdef Q_OS_IOS
if (QGuiApplication::inputMethod()->isVisible()) {
return 0;
}
#endif
return m_safeAreaMargins.bottom();
}
void PageController::setSafeAreaMargins(const QMargins &margins)
{
const QMargins previous = m_safeAreaMargins;
m_safeAreaMargins = margins;
if (previous.top() != margins.top()) {
emit safeAreaTopMarginChanged();
}
if (previous.bottom() != margins.bottom()) {
emit safeAreaBottomMarginChanged();
}
}
int PageController::getImeHeight()
@@ -1,6 +1,7 @@
#ifndef PAGECONTROLLER_H
#define PAGECONTROLLER_H
#include <QMargins>
#include <QObject>
#include <QQmlEngine>
@@ -48,6 +49,8 @@ public slots:
int getSafeAreaBottomMargin();
int getImeHeight();
void setSafeAreaMargins(const QMargins &margins);
private slots:
void onShowErrorMessage(amnezia::ErrorCode errorCode);
@@ -98,6 +101,8 @@ private:
mutable int m_cachedNavigationBarHeight = -1;
mutable bool m_cachedEdgeToEdgeEnabled = false;
mutable bool m_edgeToEdgeCached = false;
QMargins m_safeAreaMargins;
int m_imeHeight = 0;
};
+38 -23
View File
@@ -1,6 +1,5 @@
import QtQuick
import QtQuick.Controls
import QtQuick.Effects
import QtQuick.Shapes
import Style 1.0
@@ -43,27 +42,47 @@ Button {
implicitWidth: 190
implicitHeight: 190
Shape {
Item {
anchors.fill: parent
visible: root.inProgress
opacity: 0.1
preferredRendererType: Shape.CurveRenderer
ShapePath {
fillColor: AmneziaStyle.color.transparent
strokeColor: AmneziaStyle.color.borderEmphasis
strokeWidth: 1
Item {
id: diskSource
PathAngleArc {
centerX: root.width / 2
centerY: root.height / 2
radiusX: d.ringRadius
radiusY: d.ringRadius
startAngle: 0
sweepAngle: 360
anchors.fill: parent
anchors.margins: -d.glowMargin
Shape {
anchors.fill: parent
preferredRendererType: Shape.CurveRenderer
ShapePath {
fillColor: AmneziaStyle.color.transparent
strokeColor: d.ringColor
strokeWidth: 1
PathAngleArc {
centerX: diskSource.width / 2
centerY: diskSource.height / 2
radiusX: d.ringRadius
radiusY: d.ringRadius
startAngle: 0
sweepAngle: 360
}
}
}
}
ShadowType {
anchors.fill: diskSource
z: -1
source: diskSource
color: AmneziaStyle.color.shadowGlow
blur: 6
}
}
Item {
@@ -98,16 +117,12 @@ Button {
}
}
MultiEffect {
anchors.fill: ringSource
SelectionGlowType {
anchors.fill: parent
z: -1
source: ringSource
shadowEnabled: true
shadowColor: d.ringColor
shadowBlur: 0.6
shadowHorizontalOffset: 0
shadowVerticalOffset: 0
blurMax: 16
color: d.ringColor
}
RotationAnimator on rotation {
@@ -24,6 +24,7 @@ EmptyStateType {
ButtonType {
visible: root.isSearchResult || root.categoryName !== ""
size: ButtonType.Medium
variant: ButtonType.Text
text: qsTr("Show all")
+105 -9
View File
@@ -1,27 +1,123 @@
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import Style 1.0
import "../Controls2"
ListItemType {
ItemDelegate {
id: root
property bool favorite: false
property string countryFlagCode
property string subtitle
property int maximumLineCount: 2
property bool showSeparator: true
readonly property bool rowHovered: root.enabled && root.hovered && !favoriteButton.hovered
signal favoriteToggled()
implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset,
implicitContentWidth + leftPadding + rightPadding)
implicitHeight: Math.max(56, implicitContentHeight + topPadding + bottomPadding)
padding: 12
verticalPadding: 4
leftPadding: 16
leadingSlotWidth: 24
icon.source: root.countryFlagCode !== "" ? "qrc:/countriesFlags/images/flagKit/" + root.countryFlagCode + ".svg" : ""
icon.width: 21
icon.height: 15
icon.color: AmneziaStyle.color.transparent
spacing: 12
FavoriteButton {
favorite: root.favorite
hoverEnabled: true
focusPolicy: Qt.TabFocus
opacity: enabled ? 1.0 : 0.4
onClicked: root.favoriteToggled()
Accessible.name: root.text
Accessible.description: root.subtitle
Keys.onEnterPressed: root.click()
Keys.onReturnPressed: root.click()
background: Item {
implicitHeight: 56
HoverHandler {
cursorShape: Qt.PointingHandCursor
enabled: root.enabled
}
Rectangle {
anchors.fill: parent
anchors.topMargin: 4
anchors.bottomMargin: 4
radius: 16
color: {
if (root.enabled && root.down) {
return AmneziaStyle.color.bgStateLayerPressed
}
return root.rowHovered ? AmneziaStyle.color.bgStateLayer : AmneziaStyle.color.transparent
}
border.width: root.enabled && root.down || root.highlighted ? 1 : 0
border.color: AmneziaStyle.color.borderBold
Behavior on color {
ColorAnimation { duration: 150 }
}
FocusRingType {
radius: 16
visible: root.visualFocus
}
}
Rectangle {
anchors.left: parent.left
anchors.right: parent.right
anchors.bottom: parent.bottom
height: 1
visible: root.showSeparator
color: AmneziaStyle.color.borderSoft
}
}
contentItem: RowLayout {
spacing: root.spacing
Item {
Layout.preferredWidth: 24
Layout.preferredHeight: 48
visible: root.countryFlagCode !== ""
Image {
anchors.centerIn: parent
width: 21
height: 15
source: root.countryFlagCode !== "" ? "qrc:/countriesFlags/images/flagKit/" + root.countryFlagCode + ".svg" : ""
sourceSize: Qt.size(21, 15)
}
}
ListItemLabelType {
Layout.fillWidth: true
Layout.leftMargin: 4
Layout.topMargin: 10
Layout.bottomMargin: 10
title: root.text
subtitle: root.subtitle
maximumLineCount: root.maximumLineCount
}
FavoriteButton {
id: favoriteButton
favorite: root.favorite
onClicked: root.favoriteToggled()
}
}
}
+1 -1
View File
@@ -56,7 +56,7 @@ ItemDelegate {
anchors.fill: parent
radius: parent.radius
color: AmneziaStyle.color.bgStateLayer
color: root.down ? AmneziaStyle.color.bgStateLayerPressed : AmneziaStyle.color.bgStateLayer
opacity: root.enabled && (root.down || root.hovered) ? 1 : 0
Behavior on opacity {
@@ -60,6 +60,7 @@ SheetType {
Layout.rightMargin: 16
Layout.leftMargin: 16
size: ButtonType.Medium
variant: ButtonType.Text
text: qsTr("Support")
+12 -4
View File
@@ -1,5 +1,5 @@
import QtQuick
import Qt5Compat.GraphicalEffects
import QtQuick.Effects
import Style 1.0
@@ -17,8 +17,11 @@ Item {
anchors.fill: parent
layer.enabled: true
layer.effect: OpacityMask {
layer.effect: MultiEffect {
maskEnabled: true
maskSource: backdropMask
maskThresholdMin: 0.5
maskSpreadAtMin: 1.0
}
Item {
@@ -43,10 +46,14 @@ Item {
visible: false
}
FastBlur {
MultiEffect {
anchors.fill: parent
source: backdrop
radius: root.blurRadius
autoPaddingEnabled: false
blurEnabled: true
blurMax: 64
blur: root.blurRadius <= 20 ? 0.73 : 0.9
blurMultiplier: root.blurRadius <= 20 ? 0 : 0.5
}
}
}
@@ -57,6 +64,7 @@ Item {
anchors.fill: parent
radius: root.radius
visible: false
layer.enabled: true
}
Rectangle {
+48 -42
View File
@@ -59,7 +59,7 @@ AbstractButton {
anchors.fill: parent
radius: 16
color: !root.muted && root.enabled && (root.hovered || root.down) ? AmneziaStyle.color.bgStateLayer
color: !root.muted && root.enabled && (root.hovered || root.down) ? (root.down ? AmneziaStyle.color.bgStateLayerPressed : AmneziaStyle.color.bgStateLayer)
: AmneziaStyle.color.transparent
Behavior on color {
@@ -95,67 +95,73 @@ AbstractButton {
}
contentItem: RowLayout {
spacing: root.spacing
spacing: 0
IconImage {
Layout.alignment: Qt.AlignTop
Layout.preferredWidth: root.icon.width
Layout.preferredHeight: root.icon.height
visible: root.icon.source.toString() !== ""
source: root.icon.source
sourceSize: Qt.size(root.icon.width, root.icon.height)
color: root.icon.color
}
ColumnLayout {
RowLayout {
Layout.fillWidth: true
Layout.alignment: Qt.AlignTop
Layout.alignment: root.subtitle !== "" || root.footnote !== "" ? Qt.AlignTop : Qt.AlignVCenter
spacing: 4
spacing: root.spacing
H3TextType {
Layout.fillWidth: true
IconImage {
Layout.alignment: Qt.AlignTop
Layout.preferredWidth: root.icon.width
Layout.preferredHeight: root.icon.height
visible: text !== ""
text: root.text
color: root.muted ? AmneziaStyle.color.textTertiary : AmneziaStyle.color.textPrimary
visible: root.icon.source.toString() !== ""
source: root.icon.source
sourceSize: Qt.size(root.icon.width, root.icon.height)
color: root.icon.color
}
SmallTextType {
ColumnLayout {
Layout.fillWidth: true
Layout.alignment: Qt.AlignTop
visible: text !== "" && !root.muted
text: root.subtitle
textFormat: Text.RichText
spacing: 4
onLinkActivated: function(link) {
Qt.openUrlExternally(link)
H3TextType {
Layout.fillWidth: true
visible: text !== ""
text: root.text
color: root.muted ? AmneziaStyle.color.textTertiary : AmneziaStyle.color.textPrimary
}
}
CaptionTextType {
Layout.fillWidth: true
SmallTextType {
Layout.fillWidth: true
visible: text !== "" && root.muted
text: root.subtitle
textFormat: Text.RichText
color: AmneziaStyle.color.textQuaternary
}
visible: text !== "" && !root.muted
text: root.subtitle
textFormat: Text.RichText
SmallTextType {
Layout.fillWidth: true
Layout.topMargin: 8
onLinkActivated: function(link) {
Qt.openUrlExternally(link)
}
}
visible: text !== ""
text: root.footnote
color: root.muted ? AmneziaStyle.color.textQuaternary : AmneziaStyle.color.textTertiary
CaptionTextType {
Layout.fillWidth: true
visible: text !== "" && root.muted
text: root.subtitle
textFormat: Text.RichText
color: AmneziaStyle.color.textQuaternary
}
SmallTextType {
Layout.fillWidth: true
Layout.topMargin: 8
visible: text !== ""
text: root.footnote
color: root.muted ? AmneziaStyle.color.textQuaternary : AmneziaStyle.color.textTertiary
}
}
}
IconButtonType {
Layout.alignment: Qt.AlignTop
Layout.leftMargin: -root.spacing
icon.source: "qrc:/images/controls/chevron-right.svg"
icon.color: AmneziaStyle.color.iconDefault
+4 -3
View File
@@ -34,13 +34,14 @@ Button {
id: d
readonly property bool small: root.size === ButtonType.Small
readonly property bool textVariant: root.variant === ButtonType.Text
readonly property bool outlined: root.variant === ButtonType.Secondary || root.variant === ButtonType.Destructive
readonly property bool active: root.down || root.hovered
readonly property int height: root.size === ButtonType.Large ? 48 : (root.size === ButtonType.Medium ? 40 : 36)
readonly property int radius: root.size === ButtonType.Large ? 16 : (root.size === ButtonType.Medium ? 14 : 12)
readonly property int iconSize: small ? 20 : 24
readonly property int gap: root.size === ButtonType.Large ? 4 : 2
readonly property int radius: small ? 12 : (root.size === ButtonType.Medium && !textVariant ? 14 : 16)
readonly property int iconSize: small || (textVariant && root.size === ButtonType.Medium) ? 20 : 24
readonly property int gap: root.size === ButtonType.Large || textVariant ? 4 : 2
readonly property color backgroundColor: {
switch (root.variant) {
+3 -3
View File
@@ -22,14 +22,14 @@ Button {
radius: 16
color: root.checked ? AmneziaStyle.color.bgSelected : AmneziaStyle.color.bgSurfaceAlt
border.width: root.checked ? 1 : 0
border.color: AmneziaStyle.color.accentLight
border.width: root.checked || (root.hovered && !root.down) ? 1 : 0
border.color: root.checked ? AmneziaStyle.color.accentLight : AmneziaStyle.color.borderBold
Rectangle {
anchors.fill: parent
radius: parent.radius
visible: root.down || root.hovered
visible: root.down
color: AmneziaStyle.color.bgStateLayer
}
+4 -1
View File
@@ -46,7 +46,10 @@ Button {
if (root.filled) {
return root.hovered || root.down ? AmneziaStyle.color.bgSurfaceInverseAlt : AmneziaStyle.color.bgSurfaceInverse
}
return root.hovered || root.down ? AmneziaStyle.color.bgStateLayer : AmneziaStyle.color.transparent
if (root.down) {
return AmneziaStyle.color.bgStateLayerPressed
}
return root.hovered ? AmneziaStyle.color.bgStateLayer : AmneziaStyle.color.transparent
}
border.width: !root.filled && root.down ? 1 : 0
border.color: AmneziaStyle.color.borderMedium
+1 -1
View File
@@ -13,7 +13,7 @@ Button {
property string imageSource
implicitWidth: root.imageSource !== "" ? 48 : Math.max(83, implicitContentWidth + leftPadding + rightPadding)
implicitHeight: 64
implicitHeight: 56
horizontalPadding: 12
verticalPadding: 8
@@ -7,35 +7,23 @@ Item {
id: root
property T.AbstractButton control: null
property bool selected: false
property bool showSeparator: true
property color separatorColor: AmneziaStyle.color.borderSoft
readonly property bool active: root.control !== null && root.control.enabled
readonly property bool pressed: root.active && root.control.down
readonly property bool hovered: root.active && root.control.hovered
implicitHeight: 72
implicitHeight: 56
HoverHandler {
cursorShape: Qt.PointingHandCursor
enabled: root.active
}
Rectangle {
Item {
anchors.fill: parent
anchors.topMargin: 4
anchors.bottomMargin: 4
radius: 16
color: root.hovered || root.pressed ? AmneziaStyle.color.bgStateLayer : AmneziaStyle.color.transparent
border.width: root.pressed || root.selected ? 1 : 0
border.color: AmneziaStyle.color.borderBold
Behavior on color {
ColorAnimation { duration: 150 }
}
FocusRingType {
radius: 16
visible: root.control !== null && root.control.visualFocus
@@ -14,10 +14,11 @@ ColumnLayout {
property color titleColor: AmneziaStyle.color.textPrimary
property color subtitleColor: AmneziaStyle.color.textTertiary
property int maximumLineCount: 2
property int subtitleLineHeight: 20
property real textOpacity: 1.0
property bool dense: false
spacing: 4
spacing: 0
SmallTextType {
Layout.fillWidth: true
@@ -68,5 +69,6 @@ ColumnLayout {
text: root.subtitle
color: root.subtitleColor
opacity: root.textOpacity
lineHeight: root.subtitleLineHeight + LanguageUiController.getLineHeightAppend()
}
}
@@ -0,0 +1,25 @@
import QtQuick
import Style 1.0
Rectangle {
id: root
property bool hovered: false
property bool pressed: false
width: 48
height: 48
radius: 12
color: {
if (root.pressed) {
return AmneziaStyle.color.bgStateLayerPressed
}
return root.hovered ? AmneziaStyle.color.bgStateLayer : AmneziaStyle.color.transparent
}
Behavior on color {
ColorAnimation { duration: 150 }
}
}
+27 -8
View File
@@ -22,14 +22,19 @@ ItemDelegate {
property bool trailingContentVisible: trailingSlot.children.length > 0
property color separatorColor: AmneziaStyle.color.borderSoft
property int leadingSlotWidth: 48
property bool showIconBadge: false
readonly property bool rowHovered: root.interactive && root.enabled && root.hovered && !trailingHover.hovered
readonly property bool rowPressed: root.interactive && root.enabled && root.down
default property alias trailingContent: trailingSlot.data
implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset,
implicitContentWidth + leftPadding + rightPadding)
implicitHeight: Math.max(72, implicitContentHeight + topPadding + bottomPadding)
implicitHeight: Math.max(root.dense ? 72 : 56, implicitContentHeight + topPadding + bottomPadding)
padding: 12
verticalPadding: 4
spacing: 12
hoverEnabled: root.interactive
@@ -48,7 +53,6 @@ ItemDelegate {
background: ListItemBackgroundType {
control: root.interactive ? root : null
selected: root.highlighted
showSeparator: root.showSeparator
separatorColor: root.separatorColor
}
@@ -70,12 +74,22 @@ ItemDelegate {
source: root.icon.source
sourceSize: Qt.size(root.icon.width, root.icon.height)
color: root.icon.color
DotBadgeType {
anchors.horizontalCenter: parent.right
anchors.verticalCenter: parent.top
visible: root.showIconBadge
color: AmneziaStyle.color.accentDefault
}
}
}
ListItemLabelType {
Layout.fillWidth: true
Layout.leftMargin: 4
Layout.topMargin: 10
Layout.bottomMargin: 10
overline: root.overline
dense: root.dense
@@ -91,12 +105,6 @@ ItemDelegate {
if (root.locked) {
return AmneziaStyle.color.textSecondary
}
if (root.interactive && root.enabled && root.down || root.highlighted) {
return AmneziaStyle.color.textTertiary
}
if (root.enabled && root.hovered) {
return AmneziaStyle.color.textSecondary
}
return AmneziaStyle.color.textPrimary
}
}
@@ -117,6 +125,10 @@ ItemDelegate {
spacing: 0
visible: root.trailingContentVisible
HoverHandler {
id: trailingHover
}
}
Item {
@@ -125,6 +137,13 @@ ItemDelegate {
visible: root.trailingIconSource !== ""
ListItemStateLayerType {
anchors.centerIn: parent
hovered: root.rowHovered
pressed: root.rowPressed
}
IconImage {
anchors.centerIn: parent
width: 24
@@ -19,9 +19,14 @@ Popup {
color: AmneziaStyle.color.bgOverlay
}
background: Rectangle {
property Item blurSource
background: BackdropBlurType {
sourceItem: root.blurSource
blurRadius: 20
radius: 16
color: AmneziaStyle.color.bgOverlay
tintColor: Qt.alpha(AmneziaStyle.color.bgOverlay, 0.75)
borderColor: AmneziaStyle.color.transparent
}
contentItem: SpinnerType {
@@ -59,7 +59,7 @@ Item {
y: 4
visible: root.toolbarVisible
spacing: 8
spacing: 16
}
}
+27 -5
View File
@@ -57,11 +57,33 @@ Popup {
}
}
background: Rectangle {
radius: 14
color: AmneziaStyle.color.bgSurface
border.width: 1
border.color: AmneziaStyle.color.borderSoft
background: Item {
Rectangle {
id: panelShadowSource
anchors.fill: parent
radius: 14
color: AmneziaStyle.color.bgSurface
visible: false
}
ShadowType {
anchors.fill: panelShadowSource
source: panelShadowSource
verticalOffset: 8
blur: 24
color: AmneziaStyle.color.bgOverlay
}
Rectangle {
anchors.fill: parent
radius: 14
color: AmneziaStyle.color.bgSurface
border.width: 1
border.color: AmneziaStyle.color.borderSoft
}
}
contentItem: ColumnLayout {
@@ -1,5 +1,4 @@
import QtQuick
import QtQuick.Effects
import Style 1.0
@@ -25,15 +24,12 @@ Item {
}
}
MultiEffect {
anchors.fill: dot
SelectionGlowType {
anchors.fill: parent
source: dot
visible: root.checked
shadowEnabled: true
shadowColor: AmneziaStyle.color.accentLight
shadowBlur: 0.6
shadowHorizontalOffset: 0
shadowVerticalOffset: 0
color: AmneziaStyle.color.accentLight
}
Rectangle {
+18 -7
View File
@@ -18,11 +18,15 @@ RadioDelegate {
default property alias trailingContent: trailingSlot.data
readonly property bool rowHovered: root.enabled && root.hovered && !trailingHover.hovered
readonly property bool rowPressed: root.enabled && root.down
implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset,
implicitContentWidth + leftPadding + rightPadding)
implicitHeight: Math.max(72, implicitContentHeight + topPadding + bottomPadding)
implicitHeight: Math.max(56, implicitContentHeight + topPadding + bottomPadding)
padding: 12
verticalPadding: 4
leftPadding: 12 + 48 + spacing
spacing: 12
@@ -52,6 +56,13 @@ RadioDelegate {
width: 48
height: 48
ListItemStateLayerType {
anchors.centerIn: parent
hovered: root.rowHovered
pressed: root.rowPressed
}
RadioIndicatorType {
anchors.centerIn: parent
visible: root.icon.source.toString() === ""
@@ -76,6 +87,8 @@ RadioDelegate {
ListItemLabelType {
Layout.fillWidth: true
Layout.leftMargin: 4
Layout.topMargin: 10
Layout.bottomMargin: 10
title: root.text
subtitle: root.subtitle
@@ -86,12 +99,6 @@ RadioDelegate {
if (root.locked) {
return AmneziaStyle.color.textSecondary
}
if (root.enabled && root.down) {
return AmneziaStyle.color.textTertiary
}
if (root.enabled && root.hovered) {
return AmneziaStyle.color.textSecondary
}
return AmneziaStyle.color.textPrimary
}
}
@@ -112,6 +119,10 @@ RadioDelegate {
spacing: 0
visible: children.length > 0
HoverHandler {
id: trailingHover
}
}
}
}
+2 -1
View File
@@ -11,7 +11,7 @@ TextField {
implicitHeight: 44
leftPadding: 52
rightPadding: clearButton.visible ? clearButton.width + 4 : 16
rightPadding: clearButton.visible ? 52 : 16
topPadding: 10
bottomPadding: 10
verticalAlignment: TextInput.AlignVCenter
@@ -111,6 +111,7 @@ TextField {
id: clearButton
anchors.right: parent.right
anchors.rightMargin: 16 - (width - 24) / 2
anchors.verticalCenter: parent.verticalCenter
implicitWidth: Qt.platform.os === "android" ? 48 : 44
+1 -1
View File
@@ -35,7 +35,7 @@ RadioButton {
anchors.fill: parent
radius: parent.radius
color: AmneziaStyle.color.bgStateLayer
color: root.down ? AmneziaStyle.color.bgStateLayerPressed : AmneziaStyle.color.bgStateLayer
opacity: !root.checked && root.enabled && (root.hovered || root.down) ? 1 : 0
Behavior on opacity {
@@ -12,10 +12,11 @@ RadioDelegate {
implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset,
implicitContentWidth + leftPadding + rightPadding)
implicitHeight: Math.max(72, implicitContentHeight + topPadding + bottomPadding)
implicitHeight: Math.max(56, implicitContentHeight + topPadding + bottomPadding)
padding: 12
leftPadding: 16
verticalPadding: 14
hoverEnabled: true
focusPolicy: Qt.StrongFocus
@@ -31,13 +32,13 @@ RadioDelegate {
background: Item {
implicitWidth: 358
implicitHeight: 72
implicitHeight: 56
Rectangle {
anchors.fill: parent
radius: 16
color: root.enabled && !root.checked && (root.hovered || root.down) ? AmneziaStyle.color.bgStateLayer
color: root.enabled && !root.checked && (root.hovered || root.down) ? (root.down ? AmneziaStyle.color.bgStateLayerPressed : AmneziaStyle.color.bgStateLayer)
: AmneziaStyle.color.transparent
border.width: root.checked || root.down ? 1 : 0
border.color: root.checked ? AmneziaStyle.color.accentLight : AmneziaStyle.color.borderBold
@@ -0,0 +1,29 @@
import QtQuick
import QtQuick.Effects
Item {
id: root
property Item source
property color color
Repeater {
model: [[24, 1.0, 0], [24, 1.0, 0], [16, 1.0, 1]]
MultiEffect {
required property var modelData
x: root.source ? root.source.x : 0
y: root.source ? root.source.y : 0
width: root.source ? root.source.width : 0
height: root.source ? root.source.height : 0
source: root.source
shadowEnabled: true
shadowColor: root.color
blurMax: modelData[0]
shadowBlur: modelData[1]
blurMultiplier: modelData[2]
}
}
}
+39
View File
@@ -0,0 +1,39 @@
import QtQuick
import QtQuick.Effects
import Style 1.0
MultiEffect {
id: root
property real blur: 0
property color color: AmneziaStyle.color.shadowLayer1
property real horizontalOffset: 0
property real verticalOffset: 0
readonly property var blurParams: {
if (root.blur <= 3) {
return [12, 0.75]
}
if (root.blur <= 4) {
return [12, 1.0]
}
if (root.blur <= 6) {
return [20, 1.0]
}
if (root.blur <= 8) {
return [48, 0.5]
}
if (root.blur <= 15) {
return [48, 0.75]
}
return [48, 1.0]
}
shadowEnabled: true
shadowColor: root.color
shadowHorizontalOffset: root.horizontalOffset
shadowVerticalOffset: root.verticalOffset
blurMax: root.blurParams[0]
shadowBlur: root.blurParams[1]
}
+24 -13
View File
@@ -1,7 +1,7 @@
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import Qt5Compat.GraphicalEffects
import QtQuick.Effects
import Style 1.0
@@ -81,22 +81,33 @@ Popup {
visible: false
}
DropShadow {
anchors.fill: shadowSource
source: shadowSource
verticalOffset: 4
radius: 8
samples: 17
spread: 0.3
Rectangle {
id: spreadShadowSource
x: -3
y: -3 + 4
width: parent.width + 6
height: parent.height + 6
radius: 15
color: AmneziaStyle.color.shadowLayer1
visible: false
}
DropShadow {
MultiEffect {
anchors.fill: spreadShadowSource
source: spreadShadowSource
blurEnabled: true
blurMax: 48
blur: 0.5
}
ShadowType {
anchors.fill: shadowSource
source: shadowSource
verticalOffset: 1
radius: 3
samples: 7
blur: 3
color: AmneziaStyle.color.shadowLayer2
}
@@ -116,7 +127,7 @@ Popup {
property real offsetX: 0
property real offsetY: 0
implicitHeight: Math.max(content.implicitHeight, actionButton.visible ? 48 : 0)
implicitHeight: Math.max(content.implicitHeight, actionButton.visible ? 40 : 0)
transform: Translate {
x: swipe.offsetX
@@ -188,7 +199,7 @@ Popup {
visible: root.actionText !== "" || root.closable
implicitWidth: actionLabel.implicitWidth + 28
implicitHeight: 48
implicitHeight: 40
hoverEnabled: true
+3 -2
View File
@@ -35,7 +35,8 @@ Item {
BodyTextType {
Layout.fillWidth: true
Layout.alignment: Qt.AlignVCenter
Layout.alignment: Qt.AlignTop
Layout.topMargin: lineCount === 1 ? Math.max(0, (switcher.implicitHeight - lineHeight) / 2) : 0
text: root.text
color: AmneziaStyle.color.textPrimary
@@ -52,7 +53,7 @@ Item {
SwitchType {
id: switcher
Layout.alignment: Qt.AlignVCenter
Layout.alignment: Qt.AlignTop
Accessible.name: root.text
Accessible.description: root.descriptionText
+3 -8
View File
@@ -1,6 +1,5 @@
import QtQuick
import QtQuick.Controls
import QtQuick.Effects
import QtQuick.Layouts
import Style 1.0
@@ -57,16 +56,12 @@ Switch {
color: root.checked ? AmneziaStyle.color.bgStateLayerAccent : AmneziaStyle.color.bgStateLayer
}
MultiEffect {
anchors.fill: knob
SelectionGlowType {
anchors.fill: parent
source: knob
visible: root.checked
shadowEnabled: true
shadowColor: AmneziaStyle.color.accentLight
shadowBlur: 0.6
shadowHorizontalOffset: 0
shadowVerticalOffset: 0
color: AmneziaStyle.color.accentLight
}
Rectangle {
+19 -4
View File
@@ -17,6 +17,7 @@ Item {
property bool passwordToggle: false
property bool passwordRevealed: false
property bool clearable: false
property string trailingIconSource
property string buttonText
property string buttonImageSource
@@ -29,6 +30,8 @@ Item {
readonly property bool hasError: root.errorText !== ""
signal trailingClicked()
implicitWidth: content.implicitWidth
implicitHeight: content.implicitHeight
@@ -54,12 +57,12 @@ Item {
id: textField
Layout.fillWidth: true
Layout.preferredHeight: 64
Layout.preferredHeight: root.headerText !== "" ? 64 : 56
leftPadding: 16
rightPadding: actions.visible ? actions.width + 16 : 16
topPadding: root.headerText !== "" ? 28 : 20
bottomPadding: root.headerText !== "" ? 12 : 20
topPadding: root.headerText !== "" ? 28 : 16
bottomPadding: root.headerText !== "" ? 12 : 16
verticalAlignment: TextInput.AlignVCenter
color: AmneziaStyle.color.textPrimary
@@ -146,7 +149,7 @@ Item {
anchors.rightMargin: 12
anchors.verticalCenter: parent.verticalCenter
visible: clearButton.visible || eyeButton.visible
visible: root.clearable || root.passwordToggle || root.trailingIconSource !== ""
IconButtonType {
id: clearButton
@@ -174,6 +177,18 @@ Item {
onClicked: root.passwordRevealed = !root.passwordRevealed
}
IconButtonType {
id: trailingButton
implicitWidth: 40
implicitHeight: 40
visible: root.trailingIconSource !== ""
icon.source: root.trailingIconSource
onClicked: root.trailingClicked()
}
}
}
@@ -5,13 +5,14 @@ import Style 1.0
Text {
id: root
readonly property real halfLeading: Math.max(0, (root.lineHeight - fontMetrics.height) / 2)
readonly property real halfLeading: (root.lineHeight - fontMetrics.height) / 2
readonly property real overflow: Math.max(0, Math.ceil(fontMetrics.height) - root.lineHeight)
lineHeight: 14 + LanguageUiController.getLineHeightAppend()
lineHeightMode: Text.FixedHeight
topPadding: root.halfLeading
bottomPadding: -root.halfLeading
bottomPadding: -root.halfLeading - root.overflow
color: AmneziaStyle.color.textTertiary
font.pixelSize: 12
@@ -22,6 +22,7 @@ QtObject {
readonly property color bgPanelAlt: '#52525B'
readonly property color bgOverlay: '#8009090B'
readonly property color bgStateLayer: '#14FAFAFA'
readonly property color bgStateLayerPressed: '#1AFAFAFA'
readonly property color bgStateLayerAccent: '#14FDBA74'
readonly property color bgSurfaceInverse: '#E4E4E7'
readonly property color bgSurfaceInverseAlt: '#D4D4D8'
@@ -66,5 +67,6 @@ QtObject {
readonly property color shadowLayer1: '#26000000'
readonly property color shadowLayer2: '#4D000000'
readonly property color shadowGlow: '#FBB751'
}
}
-1
View File
@@ -1,7 +1,6 @@
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import Qt5Compat.GraphicalEffects
import SortFilterProxyModel 0.2
+3 -1
View File
@@ -67,6 +67,7 @@ PageType {
text: title
trailingIconSource: "qrc:/images/controls/chevron-right.svg"
icon.source: leftImagePath
showIconBadge: modelData.hasBadge === true
onClicked: clickedHandler()
}
@@ -149,7 +150,8 @@ PageType {
id: news
property string title: qsTr("News & Notifications")
readonly property string leftImagePath: NewsModel.hasUnread && SettingsController.isNewsNotificationsEnabled() ? "qrc:/images/controls/news-unread.svg" : "qrc:/images/controls/news.svg"
readonly property string leftImagePath: "qrc:/images/controls/news.svg"
readonly property bool hasBadge: NewsModel.hasUnread && SettingsController.isNewsNotificationsEnabled()
property bool isVisible: ServersUiController.hasServersFromGatewayApi
readonly property var clickedHandler: function() {
if (!ServersUiController.hasServersFromGatewayApi) {
@@ -75,6 +75,12 @@ PageType {
return
}
if (isCurrentDevice && LocalProxyController.isEnabled
&& LocalProxyController.ownerId === ServersUiController.processedServerId) {
PageController.showNotificationMessage(qsTr("Cannot unlink device while local proxy is running"))
return
}
var headerText = qsTr("Are you sure you want to unlink this device?")
var descriptionText = qsTr("This will unlink the device from your subscription. You can reconnect it anytime by pressing \"Reload API config\" in subscription settings on device.")
var yesButtonText = qsTr("Continue")
@@ -236,6 +236,7 @@ PageType {
visible: root.showRenewLink
size: ButtonType.Medium
variant: ButtonType.Text
leftImageSource: "qrc:/images/controls/refresh-cw.svg"
text: qsTr("Renew subscription")
@@ -267,6 +268,30 @@ PageType {
spacing: 0
ListItemType {
id: localProxyItem
Layout.fillWidth: true
visible: LocalProxyController.isSupported && ServersUiController.processedServerIsPremium
text: qsTr("Local proxy")
subtitle: {
if (!LocalProxyController.isEnabled) {
return qsTr("Off")
}
if (LocalProxyController.ownerId !== ServersUiController.processedServerId) {
return qsTr("In use by another server")
}
return qsTr("Running: 127.0.0.1:%1").arg(LocalProxyController.activePort > 0 ? LocalProxyController.activePort : LocalProxyController.port)
}
trailingIconSource: "qrc:/images/controls/chevron-right.svg"
onClicked: {
PageController.goToPage(PageEnum.PageSettingsLocalProxy)
}
}
ListItemType {
id: vpnKey
@@ -354,6 +379,7 @@ PageType {
Layout.alignment: Qt.AlignHCenter
size: ButtonType.Medium
variant: ButtonType.Text
destructive: true
text: qsTr("Reload API config")
@@ -387,6 +413,7 @@ PageType {
visible: root.isVisibleForAmneziaFree
size: ButtonType.Medium
variant: ButtonType.Text
destructive: true
text: qsTr("Unlink this device")
@@ -400,6 +427,9 @@ PageType {
var yesButtonFunction = function() {
if (ServersUiController.isDefaultServerCurrentlyProcessed() && ConnectionController.isConnected) {
PageController.showNotificationMessage(qsTr("Cannot unlink device during active connection"))
} else if (LocalProxyController.isEnabled
&& LocalProxyController.ownerId === ServersUiController.processedServerId) {
PageController.showNotificationMessage(qsTr("Cannot unlink device while local proxy is running"))
} else {
PageController.showBusyIndicator(true)
if (SubscriptionUiController.deactivateDevice(ServersUiController.processedServerId)) {
@@ -422,6 +452,7 @@ PageType {
Layout.topMargin: 12
Layout.bottomMargin: 16 + PageController.safeAreaBottomMargin
size: ButtonType.Medium
variant: ButtonType.Text
destructive: true
text: qsTr("Remove from application")
@@ -434,6 +465,9 @@ PageType {
var yesButtonFunction = function() {
if (ServersUiController.isDefaultServerCurrentlyProcessed() && ConnectionController.isConnected) {
PageController.showNotificationMessage(qsTr("Cannot remove server during active connection"))
} else if (LocalProxyController.isEnabled
&& LocalProxyController.ownerId === ServersUiController.processedServerId) {
PageController.showNotificationMessage(qsTr("Cannot remove server while local proxy is running"))
} else {
PageController.showBusyIndicator(true)
SubscriptionUiController.removeServer(ServersUiController.processedServerId)
@@ -0,0 +1,381 @@
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import PageEnum 1.0
import Style 1.0
import "./"
import "../Controls2"
import "../Controls2/TextTypes"
import "../Config"
PageType {
id: root
readonly property int localProxyPortMin: 1024
readonly property int localProxyPortMax: 65535
readonly property bool isEnabledForThisServer: LocalProxyController.isEnabled
&& LocalProxyController.ownerId === ServersUiController.processedServerId
readonly property bool isOwnedByOtherServer: LocalProxyController.isEnabled
&& LocalProxyController.ownerId !== ""
&& LocalProxyController.ownerId !== ServersUiController.processedServerId
property int pendingStartRequestedPort: -1
property bool pendingStartVpnWasActive: false
property bool pendingEnableAfterVpnDisconnect: false
property string pendingEnableServerId: ""
property int pendingEnableRequestedPort: -1
function clearPendingEnableAfterVpnDisconnect() {
root.pendingEnableAfterVpnDisconnect = false
root.pendingEnableServerId = ""
root.pendingEnableRequestedPort = -1
}
function enableLocalProxyNow(serverId, requestedPort, vpnWasActive) {
if (!LocalProxyController.enable(serverId, requestedPort)) {
PageController.showNotificationMessage(qsTr("Failed to enable local proxy. Check the port (%1-%2)")
.arg(root.localProxyPortMin)
.arg(root.localProxyPortMax))
return false
}
root.pendingStartRequestedPort = requestedPort
root.pendingStartVpnWasActive = vpnWasActive
startSuccessToastTimer.restart()
return true
}
function portRangeErrorText() {
return qsTr("Port must be between %1 and %2").arg(root.localProxyPortMin).arg(root.localProxyPortMax)
}
function portBusyErrorText(port) {
return qsTr("Port %1 is already in use on this device. Choose a different one").arg(port)
}
function runningPortText() {
const activePort = LocalProxyController.activePort
return (activePort > 0 ? activePort : LocalProxyController.port).toString()
}
function computePortErrorText() {
const text = portField.textField.text.trim()
if (text === "") {
return qsTr("Port is required")
}
const value = parseInt(text)
if (isNaN(value) || value < root.localProxyPortMin || value > root.localProxyPortMax) {
return root.portRangeErrorText()
}
const isOwnActivePort = root.isEnabledForThisServer && value === LocalProxyController.activePort
if (!isOwnActivePort && LocalProxyController.isPortBusy(value)) {
return root.portBusyErrorText(value)
}
return ""
}
function handleLocalProxyToggle(checked) {
if (checked) {
if (!ServersUiController.processedServerIsPremium) {
PageController.showNotificationMessage(qsTr("Local proxy is available only for Amnezia Premium"))
return
}
const wasVpnActive = ConnectionController.isConnected || ConnectionController.isConnectionInProgress
let serverId = ServersUiController.processedServerId
if (!serverId) {
serverId = ServersUiController.defaultServerId
}
if (!serverId) {
PageController.showNotificationMessage(qsTr("Unable to determine the current server"))
return
}
if (LocalProxyController.isEnabled
&& LocalProxyController.ownerId
&& LocalProxyController.ownerId !== serverId) {
PageController.showNotificationMessage(qsTr("Local proxy is already enabled for another server"))
return
}
let requestedPort = LocalProxyController.port
if (portField.textField.text.trim() !== "") {
const validationError = root.computePortErrorText()
if (validationError !== "") {
portField.errorText = validationError
return
}
requestedPort = portField.portValue()
LocalProxyController.setPort(requestedPort)
} else if (requestedPort < root.localProxyPortMin || requestedPort > root.localProxyPortMax) {
portField.errorText = root.portRangeErrorText()
return
} else if (LocalProxyController.isPortBusy(requestedPort)
&& LocalProxyController.isPortUserDefined()) {
portField.errorText = root.portBusyErrorText(requestedPort)
return
}
portField.errorText = ""
if (wasVpnActive) {
root.pendingEnableAfterVpnDisconnect = true
root.pendingEnableServerId = serverId
root.pendingEnableRequestedPort = requestedPort
ConnectionController.closeConnection()
return
}
root.enableLocalProxyNow(serverId, requestedPort, false)
} else {
startSuccessToastTimer.stop()
root.clearPendingEnableAfterVpnDisconnect()
root.pendingStartRequestedPort = -1
root.pendingStartVpnWasActive = false
LocalProxyController.disable()
PageController.showNotificationMessage(qsTr("Local proxy stopped"))
}
}
FlickableType {
id: flickable
anchors.top: parent.top
anchors.bottom: bottomBar.top
contentHeight: content.implicitHeight
ColumnLayout {
id: content
anchors.top: parent.top
anchors.left: parent.left
anchors.right: parent.right
spacing: 0
NavigationBarType {
id: navigationBar
Layout.fillWidth: true
title: qsTr("Local proxy")
description: qsTr("Used by specific apps (e.g., CensorTracker extension) via Amnezia Premium.\nOnly one can be active at a time: VPN or local proxy")
header.showSwitcher: ServersUiController.processedServerIsPremium
header.switcher.checked: root.isEnabledForThisServer
header.switcher.enabled: !root.isOwnedByOtherServer
Connections {
target: navigationBar.header
function onSwitcherToggled(checked) {
if (checked !== root.isEnabledForThisServer) {
root.handleLocalProxyToggle(checked)
}
navigationBar.header.switcher.checked = Qt.binding(function() {
return root.isEnabledForThisServer
})
}
}
}
NotificationType {
Layout.fillWidth: true
Layout.leftMargin: 16
Layout.rightMargin: 16
Layout.bottomMargin: 16
visible: root.isOwnedByOtherServer
variant: NotificationType.Warning
text: qsTr("Local proxy is already running for \"%1\". Turn it off there to use it with this server")
.arg(ServersUiController.serverName(LocalProxyController.ownerId))
}
LinkButtonType {
Layout.leftMargin: 16
Layout.rightMargin: 16
size: LinkButtonType.Medium
text: qsTr("Learn more")
onClicked: {
const path = LanguageUiController.currentLanguageName === "Русский"
? "ru/documentation/instructions/local-proxy"
: "documentation/instructions/local-proxy"
Qt.openUrlExternally(LanguageUiController.getCurrentDocsUrl(path))
}
}
TextFieldType {
id: portField
Layout.fillWidth: true
Layout.topMargin: 24
Layout.leftMargin: 16
Layout.rightMargin: 16
Layout.bottomMargin: 16
headerText: qsTr("Address and port")
placeholderText: LocalProxyController.port.toString()
trailingIconSource: root.isEnabledForThisServer ? "qrc:/images/controls/copy.svg" : ""
textField.leftPadding: 16 + portPrefix.implicitWidth
textField.inputMethodHints: Qt.ImhDigitsOnly | Qt.ImhNoPredictiveText
textField.validator: RegularExpressionValidator {
regularExpression: /^[0-9]{0,5}$/
}
onTrailingClicked: {
const portText = root.runningPortText()
GC.copyToClipBoard("127.0.0.1:" + portText)
PageController.showNotificationMessage(qsTr("Copied: 127.0.0.1:%1").arg(portText))
}
function syncPortValue() {
if (root.isEnabledForThisServer && LocalProxyController.activePort > 0) {
textField.text = LocalProxyController.activePort.toString()
} else if (LocalProxyController.isPortUserDefined()) {
textField.text = LocalProxyController.port.toString()
} else {
textField.text = ""
}
}
function portValue() {
const value = parseInt(textField.text)
return isNaN(value) ? -1 : value
}
Component.onCompleted: syncPortValue()
Text {
id: portPrefix
parent: portField.textField
x: 16
y: portField.textField.topPadding
+ (portField.textField.height - portField.textField.topPadding - portField.textField.bottomPadding - height) / 2
z: 1
text: "127.0.0.1:"
color: AmneziaStyle.color.textPrimary
font: portField.textField.font
}
}
}
}
BottomBarType {
id: bottomBar
anchors.left: parent.left
anchors.right: parent.right
anchors.bottom: parent.bottom
ButtonType {
Layout.fillWidth: true
text: qsTr("Save")
onClicked: {
const validationError = root.computePortErrorText()
portField.errorText = validationError
if (validationError !== "") {
return
}
const value = portField.portValue()
if (!LocalProxyController.setPort(value)) {
portField.errorText = root.portRangeErrorText()
return
}
PageController.showNotificationMessage(qsTr("Port saved: %1").arg(value))
portField.syncPortValue()
}
}
}
Timer {
id: startSuccessToastTimer
interval: 250
repeat: false
running: false
onTriggered: {
if (!LocalProxyController.isEnabled) {
return
}
const activePort = LocalProxyController.activePort
const requestedPort = root.pendingStartRequestedPort
const shownPort = activePort > 0 ? activePort : requestedPort
if (activePort > 0 && requestedPort > 0 && activePort !== requestedPort) {
PageController.showNotificationMessage(qsTr("Port %1 is in use — selected free port %2")
.arg(requestedPort)
.arg(activePort))
} else if (root.pendingStartVpnWasActive && shownPort > 0) {
PageController.showNotificationMessage(qsTr("VPN off. Local proxy running: 127.0.0.1:%1")
.arg(shownPort))
} else if (shownPort > 0) {
PageController.showNotificationMessage(qsTr("Local proxy running: 127.0.0.1:%1")
.arg(shownPort))
}
root.pendingStartRequestedPort = -1
root.pendingStartVpnWasActive = false
}
}
Connections {
target: ConnectionController
function onConnectionStateChanged() {
if (!root.pendingEnableAfterVpnDisconnect) {
return
}
if (ConnectionController.isConnected || ConnectionController.isConnectionInProgress) {
return
}
const serverId = root.pendingEnableServerId
const requestedPort = root.pendingEnableRequestedPort
root.clearPendingEnableAfterVpnDisconnect()
root.enableLocalProxyNow(serverId, requestedPort, true)
}
}
Connections {
target: LocalProxyController
function onStateChanged() {
if (!portField.textField.activeFocus) {
portField.syncPortValue()
}
}
function onStartFailed(message) {
startSuccessToastTimer.stop()
root.pendingStartRequestedPort = -1
root.pendingStartVpnWasActive = false
PageController.showNotificationMessage(message)
}
}
Connections {
target: ServersUiController
function onProcessedServerIdChanged() {
if (!portField.textField.activeFocus) {
portField.syncPortValue()
}
}
}
}
@@ -130,7 +130,7 @@ PageType {
visible: GC.isDesktop() && !IsMacOsNeBuild
text: qsTr("Don't have a server?")
subtitle: qsTr("Amnezia hosting. VPN servers without complicated settings and headaches")
subtitle: qsTr("Amnezia Hosting - VPN servers without complicated settings")
icon.source: "qrc:/images/controls/amnezia.svg"
+6 -2
View File
@@ -1,7 +1,7 @@
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import Qt5Compat.GraphicalEffects
import QtQuick.Effects
import PageEnum 1.0
import UpdateState 1.0
@@ -86,8 +86,11 @@ PageType {
Layout.preferredHeight: 98
layer.enabled: true
layer.effect: OpacityMask {
layer.effect: MultiEffect {
maskEnabled: true
maskSource: imageBlockMask
maskThresholdMin: 0.5
maskSpreadAtMin: 1.0
}
Image {
@@ -108,6 +111,7 @@ PageType {
anchors.fill: parent
radius: 16
visible: false
layer.enabled: true
}
BackdropBlurType {
+4
View File
@@ -61,6 +61,8 @@ Window {
maximumWidth: 600
maximumHeight: 800
flags: Qt.platform.os === "ios" ? (Qt.Window | Qt.ExpandedClientAreaHint) : Qt.Window
color: AmneziaStyle.color.bgBase
onClosing: function(close) {
@@ -306,6 +308,8 @@ Window {
id: busyIndicator
anchors.centerIn: parent
z: 1
blurSource: pageStart
}
}
+4
View File
@@ -40,6 +40,7 @@
<file>Controls2/ButtonType.qml</file>
<file>Controls2/EmptyStateType.qml</file>
<file>Controls2/ListItemBackgroundType.qml</file>
<file>Controls2/ListItemStateLayerType.qml</file>
<file>Controls2/ListItemLabelType.qml</file>
<file>Controls2/LoadingOverlayType.qml</file>
<file>Controls2/LoaderRingType.qml</file>
@@ -73,6 +74,8 @@
<file>Controls2/ListItemType.qml</file>
<file>Controls2/RadioListType.qml</file>
<file>Controls2/PageType.qml</file>
<file>Controls2/SelectionGlowType.qml</file>
<file>Controls2/ShadowType.qml</file>
<file>Controls2/SnackbarType.qml</file>
<file>Controls2/ProgressBarType.qml</file>
<file>Controls2/ScrollBarType.qml</file>
@@ -142,6 +145,7 @@
<file>Pages2/PageSettingsDns.qml</file>
<file>Pages2/PageSettingsKillSwitch.qml</file>
<file>Pages2/PageSettingsKillSwitchExceptions.qml</file>
<file>Pages2/PageSettingsLocalProxy.qml</file>
<file>Pages2/PageSettingsLogging.qml</file>
<file>Pages2/PageSettingsLogViewer.qml</file>
<file>Pages2/PageSettingsServerData.qml</file>
+1
View File
@@ -41,6 +41,7 @@ namespace PageLoader
PageSettingsApiDevices,
PageSettingsApiSubscriptionKey,
PageSettingsKillSwitchExceptions,
PageSettingsLocalProxy,
PageServiceSftpSettings,
PageServiceTorWebsiteSettings,
+1 -1
View File
@@ -14,7 +14,7 @@ class AmneziaVPN(ConanFile):
def requirements(self):
os = str(self.settings.os)
self.requires("libagw/1.0.6")
self.requires("libagw/1.0.8")
has_ne = os == "iOS" or (os == "Macos" and self.options.macos_ne)
has_service = os == "Windows" or os == "Linux" or (os == "Macos" and not has_ne)
+3
View File
@@ -40,6 +40,9 @@ class IpcInterface
SLOT(bool xrayStart(const QString &config));
SLOT(bool xrayStop());
SLOT(qint64 xrayStartOwned(const QString &config));
SLOT(bool xrayStopOwned(qint64 token));
SLOT(qint64 xrayCurrentToken());
SLOT( bool startNetworkCheck(const QString& serverIpv4Gateway, const QString& deviceIpv4Address) );
SLOT( bool stopNetworkCheck() );
+29 -2
View File
@@ -310,7 +310,7 @@ bool IpcServer::xrayStart(const QString& cfg)
qDebug() << "IpcServer::xrayStart";
#endif
return Xray::getInstance().startXray(cfg);
return Xray::getInstance().start(cfg) != 0;
}
bool IpcServer::xrayStop()
@@ -319,5 +319,32 @@ bool IpcServer::xrayStop()
qDebug() << "IpcServer::xrayStop";
#endif
return Xray::getInstance().stopXray();
return Xray::getInstance().stopAny();
}
qint64 IpcServer::xrayStartOwned(const QString& cfg)
{
#ifdef MZ_DEBUG
qDebug() << "IpcServer::xrayStartOwned";
#endif
return Xray::getInstance().start(cfg);
}
bool IpcServer::xrayStopOwned(qint64 token)
{
#ifdef MZ_DEBUG
qDebug() << "IpcServer::xrayStopOwned";
#endif
return Xray::getInstance().stop(token);
}
qint64 IpcServer::xrayCurrentToken()
{
#ifdef MZ_DEBUG
qDebug() << "IpcServer::xrayCurrentToken";
#endif
return Xray::getInstance().currentToken();
}
+3
View File
@@ -44,6 +44,9 @@ public:
virtual bool restoreResolvers() override;
virtual bool xrayStart(const QString& cfg) override;
virtual bool xrayStop() override;
virtual qint64 xrayStartOwned(const QString& cfg) override;
virtual bool xrayStopOwned(qint64 token) override;
virtual qint64 xrayCurrentToken() override;
virtual bool startNetworkCheck(const QString& serverIpv4Gateway, const QString& deviceIpv4Address) override;
virtual bool stopNetworkCheck() override;
+3 -3
View File
@@ -13,7 +13,7 @@ import shlex
class Libagw(ConanFile):
name = "libagw"
version = "1.0.6"
version = "1.0.8"
settings = "os", "arch", "compiler"
_headers = ("agw.h", "agw_types.h")
@@ -71,7 +71,7 @@ class Libagw(ConanFile):
basic_layout(self)
def build_requirements(self):
self.tool_requires("go/1.23.12")
self.tool_requires("go/1.27.1")
if self._is_windows:
self.win_bash = True
if not self.conf.get("tools.microsoft.bash:path", check_type=str):
@@ -91,7 +91,7 @@ class Libagw(ConanFile):
def source(self):
get(self, f"https://github.com/amnezia-vpn/libagw/archive/refs/tags/v{self.version}.zip",
sha256="148f421e20e31b53c7686a29a368e03720c41776facce457c55748d8b2974ddb", strip_root=True
sha256="ad36125be7ff4a77603107a0bc2194da6778d5612e649f53c9d954c742bb70db", strip_root=True
)
def generate(self):
+47
View File
@@ -31,6 +31,53 @@
#include "xray_defs.h"
#endif
qint64 Xray::start(const QString &cfg)
{
if (m_currentToken != 0) {
qDebug() << "Xray::start() engine is busy (token" << m_currentToken << "), stopping it for the new owner";
stopXray();
m_currentToken = 0;
}
if (!startXray(cfg)) {
return 0;
}
m_currentToken = ++m_lastToken;
qDebug() << "Xray::start() engine started, owner token" << m_currentToken;
return m_currentToken;
}
bool Xray::stop(qint64 token)
{
if (m_currentToken == 0) {
return true;
}
if (token == 0 || token != m_currentToken) {
qDebug() << "Xray::stop() stale owner token" << token << "(current" << m_currentToken << "), ignoring";
return true;
}
m_currentToken = 0;
return stopXray();
}
bool Xray::stopAny()
{
if (m_currentToken == 0) {
return true;
}
m_currentToken = 0;
return stopXray();
}
qint64 Xray::currentToken() const
{
return m_currentToken;
}
bool Xray::startXray(const QString &cfg)
{
qDebug() << "Xray::startXray()";
+12 -1
View File
@@ -12,10 +12,21 @@ public:
return instance;
}
// The engine is shared between consumers (VPN protocol, local proxy).
// start() returns an owner token; stop(token) is a no-op unless the token
// still owns the running engine, so a late teardown can't kill a newer owner.
qint64 start(const QString& cfg);
bool stop(qint64 token);
bool stopAny();
qint64 currentToken() const;
private:
bool startXray(const QString& cfg);
bool stopXray();
private:
qint64 m_currentToken = 0;
qint64 m_lastToken = 0;
static void ctxSockCallback(uintptr_t fd, void* ctx) {
reinterpret_cast<Xray*>(ctx)->sockCallback(fd);
}