Merge pull request #325 from amnezia-vpn/bugfix/reconnectvpn_when_dc_changed

auto reconection when current-server's defaul container hase been cha…
This commit is contained in:
Nethius 2023-09-17 17:06:02 +05:00 committed by GitHub
commit 32dda9b904
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 36 additions and 26 deletions

View file

@ -344,6 +344,8 @@ void AmneziaApplication::initControllers()
&PageController::showPassphraseRequestDrawer);
connect(m_pageController.get(), &PageController::passphraseRequestDrawerClosed, m_installController.get(),
&InstallController::setEncryptedPassphrase);
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());

View file

@ -28,6 +28,7 @@ public:
bool isUpdate = false);
ErrorCode updateContainer(const ServerCredentials &credentials, DockerContainer container,
const QJsonObject &oldConfig, QJsonObject &newConfig);
ErrorCode getAlreadyInstalledContainers(const ServerCredentials &credentials,
QMap<DockerContainer, QJsonObject> &installedContainers);

View file

@ -118,6 +118,14 @@ void ConnectionController::onConnectionStateChanged(Vpn::ConnectionState state)
emit connectionStateChanged();
}
void ConnectionController::onCurrentContainerUpdated()
{
if (m_isConnected || m_isConnectionInProgress) {
emit reconnectWithUpdatedContainer(tr("Settings updated successfully, Reconnnection..."));
openConnection();
}
}
QString ConnectionController::connectionStateText() const
{
return m_connectionStateText;

View file

@ -32,6 +32,8 @@ public slots:
QString getLastConnectionError();
void onConnectionStateChanged(Vpn::ConnectionState state);
void onCurrentContainerUpdated();
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 reconnectWithUpdatedContainer(const QString &message);
private:
QSharedPointer<ServersModel> m_serversModel;

View file

@ -259,7 +259,13 @@ void InstallController::updateContainer(QJsonObject config)
m_containersModel->setData(modelIndex, config, ContainersModel::Roles::ConfigRole);
m_protocolModel->updateModel(config);
emit updateContainerFinished();
if ((serverIndex == m_serversModel->getDefaultServerIndex())
&& (container == m_containersModel->getDefaultContainer())) {
emit currentContainerUpdated();
} else {
emit updateContainerFinished(tr("Settings updated successfully"));
}
return;
}

View file

@ -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 currentContainerUpdated();
private:
void installServer(DockerContainer container, QJsonObject &config);
void installContainer(DockerContainer container, QJsonObject &config);

View file

@ -13,14 +13,6 @@ import "../Components"
PageType {
id: root
Connections {
target: InstallController
function onUpdateContainerFinished() {
PageController.showNotificationMessage(qsTr("Settings updated successfully"))
}
}
ColumnLayout {
id: backButton

View file

@ -15,14 +15,6 @@ import "../Components"
PageType {
id: root
Connections {
target: InstallController
function onUpdateContainerFinished() {
PageController.showNotificationMessage(qsTr("Settings updated successfully"))
}
}
ColumnLayout {
id: backButton

View file

@ -13,14 +13,6 @@ import "../Components"
PageType {
id: root
Connections {
target: InstallController
function onUpdateContainerFinished() {
PageController.showNotificationMessage(qsTr("Settings updated successfully"))
}
}
ColumnLayout {
id: backButton

View file

@ -82,6 +82,18 @@ PageType {
PageController.closePage()
}
}
function onUpdateContainerFinished(message) {
PageController.showNotificationMessage(message)
}
}
Connections {
target: ConnectionController
function onReconnectWithUpdatedContainer(message) {
PageController.showNotificationMessage(message)
}
}
StackViewType {