Skip to content

Commit

Permalink
Merge pull request #325 from amnezia-vpn/bugfix/reconnectvpn_when_dc_…
Browse files Browse the repository at this point in the history
…changed

auto reconection when current-server's defaul container hase been cha…
  • Loading branch information
Nethius authored Sep 17, 2023
2 parents ff60030 + c0cb5b9 commit 32dda9b
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 26 deletions.
2 changes: 2 additions & 0 deletions client/amnezia_application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
1 change: 1 addition & 0 deletions client/core/servercontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class ServerController : public QObject
bool isUpdate = false);
ErrorCode updateContainer(const ServerCredentials &credentials, DockerContainer container,
const QJsonObject &oldConfig, QJsonObject &newConfig);

ErrorCode getAlreadyInstalledContainers(const ServerCredentials &credentials,
QMap<DockerContainer, QJsonObject> &installedContainers);

Expand Down
8 changes: 8 additions & 0 deletions client/ui/controllers/connectionController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions client/ui/controllers/connectionController.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,16 @@ public slots:
QString getLastConnectionError();
void onConnectionStateChanged(Vpn::ConnectionState state);

void onCurrentContainerUpdated();

signals:
void connectToVpn(int serverIndex, const ServerCredentials &credentials, DockerContainer container,
const QJsonObject &containerConfig);
void disconnectFromVpn();
void connectionStateChanged();

void connectionErrorOccurred(const QString &errorMessage);
void reconnectWithUpdatedContainer(const QString &message);

private:
QSharedPointer<ServersModel> m_serversModel;
Expand Down
8 changes: 7 additions & 1 deletion client/ui/controllers/installController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
4 changes: 3 additions & 1 deletion client/ui/controllers/installController.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public slots:
void installContainerFinished(const QString &finishMessage, bool isServiceInstall);
void installServerFinished(const QString &finishMessage);

void updateContainerFinished();
void updateContainerFinished(const QString& message);

void scanServerFinished(bool isInstalledContainerFound);

Expand All @@ -66,6 +66,8 @@ public slots:

void serverIsBusy(const bool isBusy);

void currentContainerUpdated();

private:
void installServer(DockerContainer container, QJsonObject &config);
void installContainer(DockerContainer container, QJsonObject &config);
Expand Down
8 changes: 0 additions & 8 deletions client/ui/qml/Pages2/PageProtocolCloakSettings.qml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,6 @@ import "../Components"
PageType {
id: root

Connections {
target: InstallController

function onUpdateContainerFinished() {
PageController.showNotificationMessage(qsTr("Settings updated successfully"))
}
}

ColumnLayout {
id: backButton

Expand Down
8 changes: 0 additions & 8 deletions client/ui/qml/Pages2/PageProtocolOpenVpnSettings.qml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,6 @@ import "../Components"
PageType {
id: root

Connections {
target: InstallController

function onUpdateContainerFinished() {
PageController.showNotificationMessage(qsTr("Settings updated successfully"))
}
}

ColumnLayout {
id: backButton

Expand Down
8 changes: 0 additions & 8 deletions client/ui/qml/Pages2/PageProtocolShadowSocksSettings.qml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,6 @@ import "../Components"
PageType {
id: root

Connections {
target: InstallController

function onUpdateContainerFinished() {
PageController.showNotificationMessage(qsTr("Settings updated successfully"))
}
}

ColumnLayout {
id: backButton

Expand Down
12 changes: 12 additions & 0 deletions client/ui/qml/Pages2/PageStart.qml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,18 @@ PageType {
PageController.closePage()
}
}

function onUpdateContainerFinished(message) {
PageController.showNotificationMessage(message)
}
}

Connections {
target: ConnectionController

function onReconnectWithUpdatedContainer(message) {
PageController.showNotificationMessage(message)
}
}

StackViewType {
Expand Down

0 comments on commit 32dda9b

Please sign in to comment.