diff --git a/client/amnezia_application.cpp b/client/amnezia_application.cpp index cdcee5f45..37f4d68b3 100644 --- a/client/amnezia_application.cpp +++ b/client/amnezia_application.cpp @@ -336,8 +336,8 @@ void AmneziaApplication::initControllers() &PageController::showPassphraseRequestDrawer); connect(m_pageController.get(), &PageController::passphraseRequestDrawerClosed, m_installController.get(), &InstallController::setEncryptedPassphrase); - connect(m_installController.get(), &InstallController::currentContainerChanged, m_connectionController.get(), - &ConnectionController::onCurrentContainerChanged); + connect(m_installController.get(), &InstallController::currentContainerUpdated, m_connectionController.get(), + &ConnectionController::onCurrentContainerUpdated); m_importController.reset(new ImportController(m_serversModel, m_containersModel, m_settings)); m_engine->rootContext()->setContextProperty("ImportController", m_importController.get()); diff --git a/client/core/servercontroller.cpp b/client/core/servercontroller.cpp index a82785ebc..b0f8146fb 100644 --- a/client/core/servercontroller.cpp +++ b/client/core/servercontroller.cpp @@ -290,11 +290,13 @@ ErrorCode ServerController::setupContainer(const ServerCredentials &credentials, return startupContainerWorker(credentials, container, config); } -ErrorCode ServerController::updateContainer(const bool reinstallRequired, - const ServerCredentials &credentials, - DockerContainer container, +ErrorCode ServerController::updateContainer(const ServerCredentials &credentials, DockerContainer container, const QJsonObject &oldConfig, QJsonObject &newConfig) { + bool reinstallRequired = isReinstallContainerRequired(container, oldConfig, newConfig); + qDebug() << "ServerController::updateContainer for container" << container << "reinstall required is" + << reinstallRequired; + if (reinstallRequired) { return setupContainer(credentials, container, newConfig, true); } else { diff --git a/client/core/servercontroller.h b/client/core/servercontroller.h index d3f242a34..3191386ca 100644 --- a/client/core/servercontroller.h +++ b/client/core/servercontroller.h @@ -26,10 +26,8 @@ class ServerController : public QObject ErrorCode removeContainer(const ServerCredentials &credentials, DockerContainer container); ErrorCode setupContainer(const ServerCredentials &credentials, DockerContainer container, QJsonObject &config, bool isUpdate = false); - ErrorCode updateContainer(const bool reinstallRequired, const ServerCredentials &credentials, - DockerContainer container, - const QJsonObject &oldConfig, - QJsonObject &newConfig); + ErrorCode updateContainer(const ServerCredentials &credentials, DockerContainer container, + const QJsonObject &oldConfig, QJsonObject &newConfig); ErrorCode getAlreadyInstalledContainers(const ServerCredentials &credentials, QMap &installedContainers); @@ -63,8 +61,6 @@ class ServerController : public QObject ErrorCode getDecryptedPrivateKey(const ServerCredentials &credentials, QString &decryptedPrivateKey, const std::function &callback); - bool isReinstallContainerRequired(DockerContainer container, const QJsonObject &oldConfig, - const QJsonObject &newConfig); private: ErrorCode installDockerWorker(const ServerCredentials &credentials, DockerContainer container); ErrorCode prepareHostWorker(const ServerCredentials &credentials, DockerContainer container, @@ -77,7 +73,8 @@ class ServerController : public QObject ErrorCode isServerPortBusy(const ServerCredentials &credentials, DockerContainer container, const QJsonObject &config); - + bool isReinstallContainerRequired(DockerContainer container, const QJsonObject &oldConfig, + const QJsonObject &newConfig); ErrorCode isUserInSudo(const ServerCredentials &credentials, DockerContainer container); ErrorCode isServerDpkgBusy(const ServerCredentials &credentials, DockerContainer container); diff --git a/client/ui/controllers/connectionController.cpp b/client/ui/controllers/connectionController.cpp index 180d96e70..77ca0f5f9 100644 --- a/client/ui/controllers/connectionController.cpp +++ b/client/ui/controllers/connectionController.cpp @@ -118,10 +118,10 @@ void ConnectionController::onConnectionStateChanged(Vpn::ConnectionState state) emit connectionStateChanged(); } -void ConnectionController::onCurrentContainerChanged() +void ConnectionController::onCurrentContainerUpdated() { - if(m_isConnected || m_isConnectionInProgress) { - emit reconnectWithChangedContainer(tr("Settings updated successfully, Reconnnection...")); + if (m_isConnected || m_isConnectionInProgress) { + emit reconnectWithUpdatedContainer(tr("Settings updated successfully, Reconnnection...")); openConnection(); } } diff --git a/client/ui/controllers/connectionController.h b/client/ui/controllers/connectionController.h index 5ee7a4ca5..7bfe0faca 100644 --- a/client/ui/controllers/connectionController.h +++ b/client/ui/controllers/connectionController.h @@ -32,7 +32,7 @@ public slots: QString getLastConnectionError(); void onConnectionStateChanged(Vpn::ConnectionState state); - void onCurrentContainerChanged(); + void onCurrentContainerUpdated(); signals: void connectToVpn(int serverIndex, const ServerCredentials &credentials, DockerContainer container, @@ -41,7 +41,7 @@ public slots: void connectionStateChanged(); void connectionErrorOccurred(const QString &errorMessage); - void reconnectWithChangedContainer(const QString &message); + void reconnectWithUpdatedContainer(const QString &message); private: QSharedPointer m_serversModel; diff --git a/client/ui/controllers/installController.cpp b/client/ui/controllers/installController.cpp index 2d82a4c2c..63510d1a0 100644 --- a/client/ui/controllers/installController.cpp +++ b/client/ui/controllers/installController.cpp @@ -254,22 +254,14 @@ void InstallController::updateContainer(QJsonObject config) ServerController serverController(m_settings); connect(&serverController, &ServerController::serverIsBusy, this, &InstallController::serverIsBusy); - bool reinstallRequired = serverController.isReinstallContainerRequired(container, oldContainerConfig, config); - auto errorCode = serverController.updateContainer(reinstallRequired, serverCredentials, container, oldContainerConfig, config); + auto errorCode = serverController.updateContainer(serverCredentials, container, oldContainerConfig, config); if (errorCode == ErrorCode::NoError) { m_containersModel->setData(modelIndex, config, ContainersModel::Roles::ConfigRole); m_protocolModel->updateModel(config); - bool isCurrentContainerChanged = false; - if (reinstallRequired && - (serverIndex == m_serversModel->getDefaultServerIndex()) && - (container == m_containersModel->getDefaultContainer()) ) { - isCurrentContainerChanged = true; - } - - - if (isCurrentContainerChanged) { - emit currentContainerChanged(); + if ((serverIndex == m_serversModel->getDefaultServerIndex()) + && (container == m_containersModel->getDefaultContainer())) { + emit currentContainerUpdated(); } else { emit updateContainerFinished(tr("Settings updated successfully")); } diff --git a/client/ui/controllers/installController.h b/client/ui/controllers/installController.h index fc924d725..a5fd28753 100644 --- a/client/ui/controllers/installController.h +++ b/client/ui/controllers/installController.h @@ -66,7 +66,7 @@ public slots: void serverIsBusy(const bool isBusy); - void currentContainerChanged(); + void currentContainerUpdated(); private: void installServer(DockerContainer container, QJsonObject &config); diff --git a/client/ui/qml/Pages2/PageProtocolCloakSettings.qml b/client/ui/qml/Pages2/PageProtocolCloakSettings.qml index 1dd9af71b..78e666a7e 100644 --- a/client/ui/qml/Pages2/PageProtocolCloakSettings.qml +++ b/client/ui/qml/Pages2/PageProtocolCloakSettings.qml @@ -13,22 +13,6 @@ import "../Components" PageType { id: root - Connections { - target: ConnectionController - - function onReconnectWithChangedContainer(message) { - PageController.showNotificationMessage(message) - } - } - - Connections { - target: InstallController - - function onUpdateContainerFinished(message) { - PageController.showNotificationMessage(message) - } - } - ColumnLayout { id: backButton diff --git a/client/ui/qml/Pages2/PageProtocolOpenVpnSettings.qml b/client/ui/qml/Pages2/PageProtocolOpenVpnSettings.qml index 741655eac..f5313e160 100644 --- a/client/ui/qml/Pages2/PageProtocolOpenVpnSettings.qml +++ b/client/ui/qml/Pages2/PageProtocolOpenVpnSettings.qml @@ -15,22 +15,6 @@ import "../Components" PageType { id: root - Connections { - target: ConnectionController - - function onReconnectWithChangedContainer(message) { - PageController.showNotificationMessage(message) - } - } - - Connections { - target: InstallController - - function onUpdateContainerFinished(message) { - PageController.showNotificationMessage(message) - } - } - ColumnLayout { id: backButton diff --git a/client/ui/qml/Pages2/PageProtocolShadowSocksSettings.qml b/client/ui/qml/Pages2/PageProtocolShadowSocksSettings.qml index f168efc16..2453281fe 100644 --- a/client/ui/qml/Pages2/PageProtocolShadowSocksSettings.qml +++ b/client/ui/qml/Pages2/PageProtocolShadowSocksSettings.qml @@ -13,23 +13,6 @@ import "../Components" PageType { id: root - - Connections { - target: ConnectionController - - function onReconnectWithChangedContainer(message) { - PageController.showNotificationMessage(message) - } - } - - Connections { - target: InstallController - - function onUpdateContainerFinished(message) { - PageController.showNotificationMessage(message) - } - } - ColumnLayout { id: backButton diff --git a/client/ui/qml/Pages2/PageStart.qml b/client/ui/qml/Pages2/PageStart.qml index 31474c127..f7020a2d4 100644 --- a/client/ui/qml/Pages2/PageStart.qml +++ b/client/ui/qml/Pages2/PageStart.qml @@ -82,6 +82,18 @@ PageType { PageController.closePage() } } + + function onUpdateContainerFinished(message) { + PageController.showNotificationMessage(message) + } + } + + Connections { + target: ConnectionController + + function onReconnectWithUpdatedContainer(message) { + PageController.showNotificationMessage(message) + } } StackViewType {