feat: add mutual exclusion between local proxy and vpn

This commit is contained in:
aiamnezia
2026-02-13 17:05:20 +04:00
parent 6518d4866e
commit 7bf16f075c
4 changed files with 23 additions and 1 deletions
@@ -159,6 +159,8 @@ void CoreController::initControllers()
m_pageController.reset(new PageController(m_serversModel, m_settings)); m_pageController.reset(new PageController(m_serversModel, m_settings));
m_engine->rootContext()->setContextProperty("PageController", m_pageController.get()); m_engine->rootContext()->setContextProperty("PageController", m_pageController.get());
connect(m_connectionController.get(), &ConnectionController::localProxyStoppedBecauseVpnTurnedOn, m_pageController.get(),
&PageController::showNotificationMessage);
m_focusController.reset(new FocusController(m_engine, this)); m_focusController.reset(new FocusController(m_engine, this));
m_engine->rootContext()->setContextProperty("FocusController", m_focusController.get()); m_engine->rootContext()->setContextProperty("FocusController", m_focusController.get());
@@ -33,6 +33,11 @@ ConnectionController::ConnectionController(const QSharedPointer<ServersModel> &s
void ConnectionController::openConnection() void ConnectionController::openConnection()
{ {
if (m_settings->isLocalProxyHttpEnabled()) {
m_settings->setLocalProxyHttpEnabled(false);
emit localProxyStoppedBecauseVpnTurnedOn(tr("Local proxy stopped because VPN was turned on"));
}
#if !defined(Q_OS_ANDROID) && !defined(Q_OS_IOS) && !defined(MACOS_NE) #if !defined(Q_OS_ANDROID) && !defined(Q_OS_IOS) && !defined(MACOS_NE)
if (!Utils::processIsRunning(Utils::executable(SERVICE_NAME, false), true)) if (!Utils::processIsRunning(Utils::executable(SERVICE_NAME, false), true))
{ {
@@ -44,6 +44,7 @@ signals:
void connectToVpn(int serverIndex, const ServerCredentials &credentials, DockerContainer container, const QJsonObject &vpnConfiguration); void connectToVpn(int serverIndex, const ServerCredentials &credentials, DockerContainer container, const QJsonObject &vpnConfiguration);
void disconnectFromVpn(); void disconnectFromVpn();
void connectionStateChanged(); void connectionStateChanged();
void localProxyStoppedBecauseVpnTurnedOn(const QString &message);
void connectionErrorOccurred(ErrorCode errorCode); void connectionErrorOccurred(ErrorCode errorCode);
void reconnectWithUpdatedContainer(const QString &message); void reconnectWithUpdatedContainer(const QString &message);
@@ -20,6 +20,7 @@ PageType {
property string portValidationError: "" property string portValidationError: ""
property int pendingStartRequestedPort: -1 property int pendingStartRequestedPort: -1
property int pendingStartAutoSelectedPort: -1 property int pendingStartAutoSelectedPort: -1
property bool pendingStartVpnWasActive: false
Component.onCompleted: root.syncSwitchState() Component.onCompleted: root.syncSwitchState()
@@ -67,6 +68,11 @@ PageType {
function handleLocalProxyToggle(checked) { function handleLocalProxyToggle(checked) {
if (checked) { if (checked) {
const wasVpnActive = ConnectionController.isConnected || ConnectionController.isConnectionInProgress
if (wasVpnActive) {
ConnectionController.closeConnection()
}
const serverUuid = ServersModel.processedServerUuid const serverUuid = ServersModel.processedServerUuid
if (!serverUuid) { if (!serverUuid) {
root.setSwitcherChecked(false) root.setSwitcherChecked(false)
@@ -110,7 +116,8 @@ PageType {
} }
} }
if (!SettingsController.enableLocalProxy(serverUuid, requestedPort)) { const portToEnable = autoSelectedPort > 0 ? autoSelectedPort : requestedPort
if (!SettingsController.enableLocalProxy(serverUuid, portToEnable)) {
root.setSwitcherChecked(false) root.setSwitcherChecked(false)
PageController.showNotificationMessage(qsTr("Failed to enable local proxy. Check the port (%1-%2).") PageController.showNotificationMessage(qsTr("Failed to enable local proxy. Check the port (%1-%2).")
.arg(root.localProxyPortMin) .arg(root.localProxyPortMin)
@@ -120,12 +127,14 @@ PageType {
} }
root.pendingStartRequestedPort = requestedPort root.pendingStartRequestedPort = requestedPort
root.pendingStartAutoSelectedPort = autoSelectedPort root.pendingStartAutoSelectedPort = autoSelectedPort
root.pendingStartVpnWasActive = wasVpnActive
startSuccessToastTimer.restart() startSuccessToastTimer.restart()
root.syncSwitchState() root.syncSwitchState()
} else { } else {
startSuccessToastTimer.stop() startSuccessToastTimer.stop()
root.pendingStartRequestedPort = -1 root.pendingStartRequestedPort = -1
root.pendingStartAutoSelectedPort = -1 root.pendingStartAutoSelectedPort = -1
root.pendingStartVpnWasActive = false
SettingsController.disableLocalProxy() SettingsController.disableLocalProxy()
root.syncSwitchState() root.syncSwitchState()
} }
@@ -334,6 +343,9 @@ PageType {
PageController.showNotificationMessage(qsTr("Port %1 is in use — selected free port %2.") PageController.showNotificationMessage(qsTr("Port %1 is in use — selected free port %2.")
.arg(root.defaultLocalProxyPort) .arg(root.defaultLocalProxyPort)
.arg(root.pendingStartAutoSelectedPort)) .arg(root.pendingStartAutoSelectedPort))
} else if (root.pendingStartVpnWasActive && root.pendingStartRequestedPort > 0) {
PageController.showNotificationMessage(qsTr("VPN turned off. Local proxy is running: 127.0.0.1:%1")
.arg(root.pendingStartRequestedPort))
} else if (root.pendingStartRequestedPort > 0) { } else if (root.pendingStartRequestedPort > 0) {
PageController.showNotificationMessage(qsTr("Local proxy is running: 127.0.0.1:%1") PageController.showNotificationMessage(qsTr("Local proxy is running: 127.0.0.1:%1")
.arg(root.pendingStartRequestedPort)) .arg(root.pendingStartRequestedPort))
@@ -341,6 +353,7 @@ PageType {
root.pendingStartRequestedPort = -1 root.pendingStartRequestedPort = -1
root.pendingStartAutoSelectedPort = -1 root.pendingStartAutoSelectedPort = -1
root.pendingStartVpnWasActive = false
} }
} }
@@ -359,6 +372,7 @@ PageType {
startSuccessToastTimer.stop() startSuccessToastTimer.stop()
root.pendingStartRequestedPort = -1 root.pendingStartRequestedPort = -1
root.pendingStartAutoSelectedPort = -1 root.pendingStartAutoSelectedPort = -1
root.pendingStartVpnWasActive = false
PageController.showNotificationMessage(message) PageController.showNotificationMessage(message)
root.syncSwitchState() root.syncSwitchState()
} }