mirror of
https://github.com/amnezia-vpn/amnezia-client.git
synced 2026-06-23 02:00:20 +07:00
fix: revert API country selection on server switch failure
This commit is contained in:
@@ -484,6 +484,12 @@ ErrorCode SubscriptionController::updateServiceFromGateway(const QString &server
|
|||||||
return ErrorCode::NoError;
|
return ErrorCode::NoError;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SubscriptionController::restoreApiV2Config(const QString &serverId, const ApiV2ServerConfig &config)
|
||||||
|
{
|
||||||
|
const QJsonObject json = config.toJson();
|
||||||
|
m_serversRepository->editServer(serverId, json, serverConfigUtils::configTypeFromJson(json));
|
||||||
|
}
|
||||||
|
|
||||||
ErrorCode SubscriptionController::deactivateDevice(const QString &serverId)
|
ErrorCode SubscriptionController::deactivateDevice(const QString &serverId)
|
||||||
{
|
{
|
||||||
auto apiV2 = m_serversRepository->apiV2Config(serverId);
|
auto apiV2 = m_serversRepository->apiV2Config(serverId);
|
||||||
|
|||||||
@@ -68,6 +68,8 @@ public:
|
|||||||
|
|
||||||
ErrorCode updateServiceFromGateway(const QString &serverId, const QString &newCountryCode, bool isConnectEvent);
|
ErrorCode updateServiceFromGateway(const QString &serverId, const QString &newCountryCode, bool isConnectEvent);
|
||||||
|
|
||||||
|
void restoreApiV2Config(const QString &serverId, const ApiV2ServerConfig &config);
|
||||||
|
|
||||||
ErrorCode deactivateDevice(const QString &serverId);
|
ErrorCode deactivateDevice(const QString &serverId);
|
||||||
|
|
||||||
ErrorCode deactivateExternalDevice(const QString &serverId, const QString &uuid, const QString &serverCountryCode);
|
ErrorCode deactivateExternalDevice(const QString &serverId, const QString &uuid, const QString &serverCountryCode);
|
||||||
|
|||||||
@@ -95,6 +95,7 @@ void CoreSignalHandlers::initErrorMessagesHandler()
|
|||||||
});
|
});
|
||||||
|
|
||||||
connect(m_coreController->m_connectionUiController, &ConnectionUiController::serverSwitchFailed, this, [this]() {
|
connect(m_coreController->m_connectionUiController, &ConnectionUiController::serverSwitchFailed, this, [this]() {
|
||||||
|
m_coreController->m_subscriptionUiController->revertLastCountryChange();
|
||||||
emit m_coreController->m_pageController->showNotificationMessage(
|
emit m_coreController->m_pageController->showNotificationMessage(
|
||||||
tr("Failed to switch server. Existing connection maintained."));
|
tr("Failed to switch server. Existing connection maintained."));
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -418,7 +418,8 @@ bool SubscriptionUiController::updateServiceFromGateway(const QString &serverId,
|
|||||||
{
|
{
|
||||||
bool isConnectEvent = newCountryCode.isEmpty() && newCountryName.isEmpty() && !reloadServiceConfig;
|
bool isConnectEvent = newCountryCode.isEmpty() && newCountryName.isEmpty() && !reloadServiceConfig;
|
||||||
bool wasSubscriptionExpired = false;
|
bool wasSubscriptionExpired = false;
|
||||||
if (const auto oldApiV2 = m_serversController->apiV2Config(serverId)) {
|
const auto oldApiV2 = m_serversController->apiV2Config(serverId);
|
||||||
|
if (oldApiV2) {
|
||||||
wasSubscriptionExpired = oldApiV2->apiConfig.subscriptionExpiredByServer
|
wasSubscriptionExpired = oldApiV2->apiConfig.subscriptionExpiredByServer
|
||||||
|| oldApiV2->apiConfig.isSubscriptionExpired();
|
|| oldApiV2->apiConfig.isSubscriptionExpired();
|
||||||
}
|
}
|
||||||
@@ -426,6 +427,10 @@ bool SubscriptionUiController::updateServiceFromGateway(const QString &serverId,
|
|||||||
ErrorCode errorCode = m_subscriptionController->updateServiceFromGateway(serverId, newCountryCode, isConnectEvent);
|
ErrorCode errorCode = m_subscriptionController->updateServiceFromGateway(serverId, newCountryCode, isConnectEvent);
|
||||||
|
|
||||||
if (errorCode == ErrorCode::NoError) {
|
if (errorCode == ErrorCode::NoError) {
|
||||||
|
if (!newCountryCode.isEmpty() && oldApiV2) {
|
||||||
|
m_previousCountryServerId = serverId;
|
||||||
|
m_previousApiV2Config = oldApiV2;
|
||||||
|
}
|
||||||
if (wasSubscriptionExpired) {
|
if (wasSubscriptionExpired) {
|
||||||
emit subscriptionRefreshNeeded();
|
emit subscriptionRefreshNeeded();
|
||||||
}
|
}
|
||||||
@@ -447,6 +452,20 @@ bool SubscriptionUiController::updateServiceFromGateway(const QString &serverId,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SubscriptionUiController::revertLastCountryChange()
|
||||||
|
{
|
||||||
|
if (m_previousCountryServerId.isEmpty() || !m_previousApiV2Config) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const QString serverId = m_previousCountryServerId;
|
||||||
|
const ApiV2ServerConfig cfg = *m_previousApiV2Config;
|
||||||
|
m_previousCountryServerId.clear();
|
||||||
|
m_previousApiV2Config.reset();
|
||||||
|
|
||||||
|
m_subscriptionController->restoreApiV2Config(serverId, cfg);
|
||||||
|
m_apiCountryModel->updateModel(cfg.apiConfig.availableCountries,
|
||||||
|
cfg.apiConfig.serverCountryCode);
|
||||||
|
}
|
||||||
|
|
||||||
bool SubscriptionUiController::deactivateDevice(const QString &serverId)
|
bool SubscriptionUiController::deactivateDevice(const QString &serverId)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ public slots:
|
|||||||
bool importTrialFromGateway(const QString &email);
|
bool importTrialFromGateway(const QString &email);
|
||||||
bool updateServiceFromGateway(const QString &serverId, const QString &newCountryCode, const QString &newCountryName,
|
bool updateServiceFromGateway(const QString &serverId, const QString &newCountryCode, const QString &newCountryName,
|
||||||
bool reloadServiceConfig = false);
|
bool reloadServiceConfig = false);
|
||||||
|
void revertLastCountryChange();
|
||||||
bool deactivateDevice(const QString &serverId);
|
bool deactivateDevice(const QString &serverId);
|
||||||
bool deactivateExternalDevice(const QString &serverId, const QString &uuid, const QString &serverCountryCode);
|
bool deactivateExternalDevice(const QString &serverId, const QString &uuid, const QString &serverCountryCode);
|
||||||
|
|
||||||
@@ -125,6 +126,9 @@ private:
|
|||||||
ApiDevicesModel* m_apiDevicesModel;
|
ApiDevicesModel* m_apiDevicesModel;
|
||||||
SettingsController* m_settingsController;
|
SettingsController* m_settingsController;
|
||||||
ConnectionController* m_connectionController;
|
ConnectionController* m_connectionController;
|
||||||
|
|
||||||
|
QString m_previousCountryServerId;
|
||||||
|
std::optional<ApiV2ServerConfig> m_previousApiV2Config;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SUBSCRIPTIONUICONTROLLER_H
|
#endif // SUBSCRIPTIONUICONTROLLER_H
|
||||||
|
|||||||
Reference in New Issue
Block a user