auto reconection when current-server's defaul container hase been changed
This commit is contained in:
parent
f11c65c393
commit
bfc8c10f3d
10 changed files with 74 additions and 18 deletions
|
@ -336,6 +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);
|
||||
|
||||
m_importController.reset(new ImportController(m_serversModel, m_containersModel, m_settings));
|
||||
m_engine->rootContext()->setContextProperty("ImportController", m_importController.get());
|
||||
|
|
|
@ -290,13 +290,11 @@ ErrorCode ServerController::setupContainer(const ServerCredentials &credentials,
|
|||
return startupContainerWorker(credentials, container, config);
|
||||
}
|
||||
|
||||
ErrorCode ServerController::updateContainer(const ServerCredentials &credentials, DockerContainer container,
|
||||
ErrorCode ServerController::updateContainer(const bool reinstallRequired,
|
||||
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 {
|
||||
|
|
|
@ -26,8 +26,11 @@ public:
|
|||
ErrorCode removeContainer(const ServerCredentials &credentials, DockerContainer container);
|
||||
ErrorCode setupContainer(const ServerCredentials &credentials, DockerContainer container, QJsonObject &config,
|
||||
bool isUpdate = false);
|
||||
ErrorCode updateContainer(const ServerCredentials &credentials, DockerContainer container,
|
||||
const QJsonObject &oldConfig, QJsonObject &newConfig);
|
||||
ErrorCode updateContainer(const bool reinstallRequired, const ServerCredentials &credentials,
|
||||
DockerContainer container,
|
||||
const QJsonObject &oldConfig,
|
||||
QJsonObject &newConfig);
|
||||
|
||||
ErrorCode getAlreadyInstalledContainers(const ServerCredentials &credentials,
|
||||
QMap<DockerContainer, QJsonObject> &installedContainers);
|
||||
|
||||
|
@ -60,6 +63,8 @@ public:
|
|||
ErrorCode getDecryptedPrivateKey(const ServerCredentials &credentials, QString &decryptedPrivateKey,
|
||||
const std::function<QString()> &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,
|
||||
|
@ -72,8 +77,7 @@ private:
|
|||
|
||||
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);
|
||||
|
||||
|
|
|
@ -118,6 +118,14 @@ void ConnectionController::onConnectionStateChanged(Vpn::ConnectionState state)
|
|||
emit connectionStateChanged();
|
||||
}
|
||||
|
||||
void ConnectionController::onCurrentContainerChanged()
|
||||
{
|
||||
if(m_isConnected || m_isConnectionInProgress) {
|
||||
emit reconnectWithChangedContainer(tr("Settings updated successfully, Reconnnection..."));
|
||||
openConnection();
|
||||
}
|
||||
}
|
||||
|
||||
QString ConnectionController::connectionStateText() const
|
||||
{
|
||||
return m_connectionStateText;
|
||||
|
|
|
@ -32,6 +32,8 @@ public slots:
|
|||
QString getLastConnectionError();
|
||||
void onConnectionStateChanged(Vpn::ConnectionState state);
|
||||
|
||||
void onCurrentContainerChanged();
|
||||
|
||||
signals:
|
||||
void connectToVpn(int serverIndex, const ServerCredentials &credentials, DockerContainer container,
|
||||
const QJsonObject &containerConfig);
|
||||
|
@ -39,6 +41,7 @@ signals:
|
|||
void connectionStateChanged();
|
||||
|
||||
void connectionErrorOccurred(const QString &errorMessage);
|
||||
void reconnectWithChangedContainer(const QString &message);
|
||||
|
||||
private:
|
||||
QSharedPointer<ServersModel> m_serversModel;
|
||||
|
|
|
@ -254,12 +254,26 @@ void InstallController::updateContainer(QJsonObject config)
|
|||
ServerController serverController(m_settings);
|
||||
connect(&serverController, &ServerController::serverIsBusy, this, &InstallController::serverIsBusy);
|
||||
|
||||
auto errorCode = serverController.updateContainer(serverCredentials, container, oldContainerConfig, config);
|
||||
bool reinstallRequired = serverController.isReinstallContainerRequired(container, oldContainerConfig, config);
|
||||
auto errorCode = serverController.updateContainer(reinstallRequired, serverCredentials, container, oldContainerConfig, config);
|
||||
if (errorCode == ErrorCode::NoError) {
|
||||
m_containersModel->setData(modelIndex, config, ContainersModel::Roles::ConfigRole);
|
||||
m_protocolModel->updateModel(config);
|
||||
|
||||
emit updateContainerFinished();
|
||||
bool isCurrentContainerChanged = false;
|
||||
if (reinstallRequired &&
|
||||
(serverIndex == m_serversModel->getDefaultServerIndex()) &&
|
||||
(container == m_containersModel->getDefaultContainer()) ) {
|
||||
isCurrentContainerChanged = true;
|
||||
}
|
||||
|
||||
|
||||
if (isCurrentContainerChanged) {
|
||||
emit currentContainerChanged();
|
||||
} else {
|
||||
emit updateContainerFinished(tr("Settings updated successfully"));
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -49,7 +49,7 @@ signals:
|
|||
void installContainerFinished(const QString &finishMessage, bool isServiceInstall);
|
||||
void installServerFinished(const QString &finishMessage);
|
||||
|
||||
void updateContainerFinished();
|
||||
void updateContainerFinished(const QString& message);
|
||||
|
||||
void scanServerFinished(bool isInstalledContainerFound);
|
||||
|
||||
|
@ -66,6 +66,8 @@ signals:
|
|||
|
||||
void serverIsBusy(const bool isBusy);
|
||||
|
||||
void currentContainerChanged();
|
||||
|
||||
private:
|
||||
void installServer(DockerContainer container, QJsonObject &config);
|
||||
void installContainer(DockerContainer container, QJsonObject &config);
|
||||
|
|
|
@ -13,11 +13,19 @@ import "../Components"
|
|||
PageType {
|
||||
id: root
|
||||
|
||||
Connections {
|
||||
target: ConnectionController
|
||||
|
||||
function onReconnectWithChangedContainer(message) {
|
||||
PageController.showNotificationMessage(message)
|
||||
}
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: InstallController
|
||||
|
||||
function onUpdateContainerFinished() {
|
||||
PageController.showNotificationMessage(qsTr("Settings updated successfully"))
|
||||
function onUpdateContainerFinished(message) {
|
||||
PageController.showNotificationMessage(message)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -15,11 +15,19 @@ import "../Components"
|
|||
PageType {
|
||||
id: root
|
||||
|
||||
Connections {
|
||||
target: ConnectionController
|
||||
|
||||
function onReconnectWithChangedContainer(message) {
|
||||
PageController.showNotificationMessage(message)
|
||||
}
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: InstallController
|
||||
|
||||
function onUpdateContainerFinished() {
|
||||
PageController.showNotificationMessage(qsTr("Settings updated successfully"))
|
||||
function onUpdateContainerFinished(message) {
|
||||
PageController.showNotificationMessage(message)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -13,11 +13,20 @@ import "../Components"
|
|||
PageType {
|
||||
id: root
|
||||
|
||||
|
||||
Connections {
|
||||
target: ConnectionController
|
||||
|
||||
function onReconnectWithChangedContainer(message) {
|
||||
PageController.showNotificationMessage(message)
|
||||
}
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: InstallController
|
||||
|
||||
function onUpdateContainerFinished() {
|
||||
PageController.showNotificationMessage(qsTr("Settings updated successfully"))
|
||||
function onUpdateContainerFinished(message) {
|
||||
PageController.showNotificationMessage(message)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue