From 79edbe52a3e22de1f036abc3ee330345825259cf Mon Sep 17 00:00:00 2001 From: Vladyslav Miachkov <34045014+fameowner99@users.noreply.github.com> Date: Thu, 18 Apr 2024 14:49:57 +0300 Subject: [PATCH] Prevent editing active container (#749) * Prevent editing active container * Prevent clear active container's cache --- client/ui/models/servers_model.cpp | 9 +-------- client/ui/qml/Pages2/PageProtocolAwgSettings.qml | 6 ++++++ client/ui/qml/Pages2/PageProtocolCloakSettings.qml | 6 ++++++ client/ui/qml/Pages2/PageProtocolOpenVpnSettings.qml | 6 ++++++ client/ui/qml/Pages2/PageProtocolShadowSocksSettings.qml | 6 ++++++ client/ui/qml/Pages2/PageProtocolWireGuardSettings.qml | 6 ++++++ client/ui/qml/Pages2/PageProtocolXraySettings.qml | 6 ++++++ client/ui/qml/Pages2/PageSettingsServerProtocol.qml | 6 ++++++ 8 files changed, 43 insertions(+), 8 deletions(-) diff --git a/client/ui/models/servers_model.cpp b/client/ui/models/servers_model.cpp index 61af8c8d..99b38234 100644 --- a/client/ui/models/servers_model.cpp +++ b/client/ui/models/servers_model.cpp @@ -384,13 +384,6 @@ void ServersModel::updateContainerConfig(const int containerIndex, const QJsonOb } server.insert(config_key::containers, containers); - - auto defaultContainer = server.value(config_key::defaultContainer).toString(); - if ((ContainerProps::containerFromString(defaultContainer) == DockerContainer::None - || ContainerProps::containerService(container) != ServiceType::Other)) { - server.insert(config_key::defaultContainer, ContainerProps::containerToString(container)); - } - editServer(server, m_processedServerIndex); } @@ -630,4 +623,4 @@ bool ServersModel::isDefaultServerDefaultContainerHasSplitTunneling() } return false; -} +} \ No newline at end of file diff --git a/client/ui/qml/Pages2/PageProtocolAwgSettings.qml b/client/ui/qml/Pages2/PageProtocolAwgSettings.qml index 32120627..a00378c1 100644 --- a/client/ui/qml/Pages2/PageProtocolAwgSettings.qml +++ b/client/ui/qml/Pages2/PageProtocolAwgSettings.qml @@ -352,6 +352,12 @@ PageType { var yesButtonFunction = function() { forceActiveFocus() + + if (ConnectionController.isConnected && ServersModel.getDefaultServerData("defaultContainer") === ContainersModel.getProcessedContainerIndex()) { + PageController.showNotificationMessage(qsTr("Unable change settings while there is an active connection")) + return + } + PageController.goToPage(PageEnum.PageSetupWizardInstalling); InstallController.updateContainer(AwgConfigModel.getConfig()) } diff --git a/client/ui/qml/Pages2/PageProtocolCloakSettings.qml b/client/ui/qml/Pages2/PageProtocolCloakSettings.qml index 729f248f..9b23454c 100644 --- a/client/ui/qml/Pages2/PageProtocolCloakSettings.qml +++ b/client/ui/qml/Pages2/PageProtocolCloakSettings.qml @@ -178,6 +178,12 @@ PageType { clickedFunc: function() { forceActiveFocus() + + if (ConnectionController.isConnected && ServersModel.getDefaultServerData("defaultContainer") === ContainersModel.getProcessedContainerIndex()) { + PageController.showNotificationMessage(qsTr("Unable change settings while there is an active connection")) + return + } + PageController.goToPage(PageEnum.PageSetupWizardInstalling); InstallController.updateContainer(CloakConfigModel.getConfig()) } diff --git a/client/ui/qml/Pages2/PageProtocolOpenVpnSettings.qml b/client/ui/qml/Pages2/PageProtocolOpenVpnSettings.qml index dd3b5a0d..95e2581f 100644 --- a/client/ui/qml/Pages2/PageProtocolOpenVpnSettings.qml +++ b/client/ui/qml/Pages2/PageProtocolOpenVpnSettings.qml @@ -376,6 +376,12 @@ PageType { clickedFunc: function() { forceActiveFocus() + + if (ConnectionController.isConnected && ServersModel.getDefaultServerData("defaultContainer") === ContainersModel.getProcessedContainerIndex()) { + PageController.showNotificationMessage(qsTr("Unable change settings while there is an active connection")) + return + } + PageController.goToPage(PageEnum.PageSetupWizardInstalling); InstallController.updateContainer(OpenVpnConfigModel.getConfig()) } diff --git a/client/ui/qml/Pages2/PageProtocolShadowSocksSettings.qml b/client/ui/qml/Pages2/PageProtocolShadowSocksSettings.qml index 4847036d..b2a1379b 100644 --- a/client/ui/qml/Pages2/PageProtocolShadowSocksSettings.qml +++ b/client/ui/qml/Pages2/PageProtocolShadowSocksSettings.qml @@ -158,6 +158,12 @@ PageType { clickedFunc: function() { forceActiveFocus() + + if (ConnectionController.isConnected && ServersModel.getDefaultServerData("defaultContainer") === ContainersModel.getProcessedContainerIndex()) { + PageController.showNotificationMessage(qsTr("Unable change settings while there is an active connection")) + return + } + PageController.goToPage(PageEnum.PageSetupWizardInstalling); InstallController.updateContainer(ShadowSocksConfigModel.getConfig()) } diff --git a/client/ui/qml/Pages2/PageProtocolWireGuardSettings.qml b/client/ui/qml/Pages2/PageProtocolWireGuardSettings.qml index fda33940..8c3f1865 100644 --- a/client/ui/qml/Pages2/PageProtocolWireGuardSettings.qml +++ b/client/ui/qml/Pages2/PageProtocolWireGuardSettings.qml @@ -126,6 +126,12 @@ PageType { onClicked: { forceActiveFocus() + + if (ConnectionController.isConnected && ServersModel.getDefaultServerData("defaultContainer") === ContainersModel.getProcessedContainerIndex()) { + PageController.showNotificationMessage(qsTr("Unable change settings while there is an active connection")) + return + } + PageController.goToPage(PageEnum.PageSetupWizardInstalling); InstallController.updateContainer(WireGuardConfigModel.getConfig()) } diff --git a/client/ui/qml/Pages2/PageProtocolXraySettings.qml b/client/ui/qml/Pages2/PageProtocolXraySettings.qml index c47ff310..a2d2d3f4 100644 --- a/client/ui/qml/Pages2/PageProtocolXraySettings.qml +++ b/client/ui/qml/Pages2/PageProtocolXraySettings.qml @@ -107,6 +107,12 @@ PageType { onClicked: { forceActiveFocus() + + if (ConnectionController.isConnected && ServersModel.getDefaultServerData("defaultContainer") === ContainersModel.getProcessedContainerIndex()) { + PageController.showNotificationMessage(qsTr("Unable change settings while there is an active connection")) + return + } + PageController.goToPage(PageEnum.PageSetupWizardInstalling); InstallController.updateContainer(XrayConfigModel.getConfig()) } diff --git a/client/ui/qml/Pages2/PageSettingsServerProtocol.qml b/client/ui/qml/Pages2/PageSettingsServerProtocol.qml index 36b8a1df..916cbf76 100644 --- a/client/ui/qml/Pages2/PageSettingsServerProtocol.qml +++ b/client/ui/qml/Pages2/PageSettingsServerProtocol.qml @@ -105,6 +105,12 @@ PageType { var noButtonText = qsTr("Cancel") var yesButtonFunction = function() { + if (ConnectionController.isConnected && ServersModel.getDefaultServerData("defaultContainer") === ContainersModel.getProcessedContainerIndex()) { + var message = qsTr("Unable to clear %1 profile while there is an active connection").arg(ContainersModel.getProcessedContainerName()) + PageController.showNotificationMessage(message) + return + } + PageController.showBusyIndicator(true) InstallController.clearCachedProfile() PageController.showBusyIndicator(false)