parent
8cb298937f
commit
b05a5ee1c6
5 changed files with 28 additions and 19 deletions
|
@ -385,7 +385,13 @@ void AmneziaApplication::initControllers()
|
||||||
m_engine->rootContext()->setContextProperty("ApiController", m_apiController.get());
|
m_engine->rootContext()->setContextProperty("ApiController", m_apiController.get());
|
||||||
connect(m_apiController.get(), &ApiController::updateStarted, this,
|
connect(m_apiController.get(), &ApiController::updateStarted, this,
|
||||||
[this]() { emit m_vpnConnection->connectionStateChanged(Vpn::ConnectionState::Connecting); });
|
[this]() { emit m_vpnConnection->connectionStateChanged(Vpn::ConnectionState::Connecting); });
|
||||||
connect(m_apiController.get(), &ApiController::errorOccurred, this,
|
connect(m_apiController.get(), &ApiController::errorOccurred, this, [this](const QString &errorMessage) {
|
||||||
[this]() { emit m_vpnConnection->connectionStateChanged(Vpn::ConnectionState::Disconnected); });
|
if (m_connectionController->isConnectionInProgress()) {
|
||||||
connect(m_apiController.get(), &ApiController::updateFinished, m_connectionController.get(), &ConnectionController::toggleConnection);
|
emit m_pageController->showErrorMessage(errorMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
emit m_vpnConnection->connectionStateChanged(Vpn::ConnectionState::Disconnected);
|
||||||
|
});
|
||||||
|
connect(m_apiController.get(), &ApiController::updateFinished, m_connectionController.get(),
|
||||||
|
&ConnectionController::toggleConnection);
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,14 +70,17 @@ QJsonObject ApiController::fillApiPayload(const QString &protocol, const ApiCont
|
||||||
void ApiController::updateServerConfigFromApi()
|
void ApiController::updateServerConfigFromApi()
|
||||||
{
|
{
|
||||||
QtConcurrent::run([this]() {
|
QtConcurrent::run([this]() {
|
||||||
|
if (m_isConfigUpdateStarted) {
|
||||||
|
emit updateFinished(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
auto serverConfig = m_serversModel->getDefaultServerConfig();
|
auto serverConfig = m_serversModel->getDefaultServerConfig();
|
||||||
auto containerConfig = serverConfig.value(config_key::containers).toArray();
|
auto containerConfig = serverConfig.value(config_key::containers).toArray();
|
||||||
|
|
||||||
bool isConfigUpdateStarted = false;
|
|
||||||
|
|
||||||
if (serverConfig.value(config_key::configVersion).toInt() && containerConfig.isEmpty()) {
|
if (serverConfig.value(config_key::configVersion).toInt() && containerConfig.isEmpty()) {
|
||||||
emit updateStarted();
|
emit updateStarted();
|
||||||
isConfigUpdateStarted = true;
|
m_isConfigUpdateStarted = true;
|
||||||
|
|
||||||
QNetworkAccessManager manager;
|
QNetworkAccessManager manager;
|
||||||
|
|
||||||
|
@ -110,6 +113,12 @@ void ApiController::updateServerConfigFromApi()
|
||||||
QByteArray ba = QByteArray::fromBase64(data.toUtf8(),
|
QByteArray ba = QByteArray::fromBase64(data.toUtf8(),
|
||||||
QByteArray::Base64UrlEncoding | QByteArray::OmitTrailingEquals);
|
QByteArray::Base64UrlEncoding | QByteArray::OmitTrailingEquals);
|
||||||
|
|
||||||
|
if (ba.isEmpty()) {
|
||||||
|
emit errorOccurred(errorString(ApiConfigDownloadError));
|
||||||
|
m_isConfigUpdateStarted = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
QByteArray ba_uncompressed = qUncompress(ba);
|
QByteArray ba_uncompressed = qUncompress(ba);
|
||||||
if (!ba_uncompressed.isEmpty()) {
|
if (!ba_uncompressed.isEmpty()) {
|
||||||
ba = ba_uncompressed;
|
ba = ba_uncompressed;
|
||||||
|
@ -133,11 +142,13 @@ void ApiController::updateServerConfigFromApi()
|
||||||
qDebug() << reply->error();
|
qDebug() << reply->error();
|
||||||
qDebug() << reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
|
qDebug() << reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
|
||||||
emit errorOccurred(errorString(ApiConfigDownloadError));
|
emit errorOccurred(errorString(ApiConfigDownloadError));
|
||||||
|
m_isConfigUpdateStarted = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
emit updateFinished(isConfigUpdateStarted);
|
emit updateFinished(m_isConfigUpdateStarted);
|
||||||
|
m_isConfigUpdateStarted = false;
|
||||||
return;
|
return;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,6 +39,8 @@ private:
|
||||||
|
|
||||||
QSharedPointer<ServersModel> m_serversModel;
|
QSharedPointer<ServersModel> m_serversModel;
|
||||||
QSharedPointer<ContainersModel> m_containersModel;
|
QSharedPointer<ContainersModel> m_containersModel;
|
||||||
|
|
||||||
|
bool m_isConfigUpdateStarted = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // APICONTROLLER_H
|
#endif // APICONTROLLER_H
|
||||||
|
|
|
@ -138,9 +138,7 @@ Button {
|
||||||
}
|
}
|
||||||
|
|
||||||
onClicked: {
|
onClicked: {
|
||||||
if (!ConnectionController.isConnectionInProgress) {
|
ServersModel.setCurrentlyProcessedServerIndex(ServersModel.defaultIndex)
|
||||||
ServersModel.setCurrentlyProcessedServerIndex(ServersModel.defaultIndex)
|
ApiController.updateServerConfigFromApi()
|
||||||
ApiController.updateServerConfigFromApi()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -113,14 +113,6 @@ PageType {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Connections {
|
|
||||||
target: ApiController
|
|
||||||
|
|
||||||
function onErrorOccurred(errorMessage) {
|
|
||||||
PageController.showErrorMessage(errorMessage)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
StackViewType {
|
StackViewType {
|
||||||
id: tabBarStackView
|
id: tabBarStackView
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue