mirror of
https://github.com/amnezia-vpn/amnezia-client.git
synced 2026-05-17 00:06:05 +03:00
refactor: deactivate api config before remove (#2569)
Co-authored-by: vkamn <vk@amnezia.org>
This commit is contained in:
@@ -679,6 +679,27 @@ void SubscriptionController::removeApiConfig(const QString &serverId)
|
||||
serverConfigUtils::configTypeFromJson(apiV2->toJson()));
|
||||
}
|
||||
|
||||
bool SubscriptionController::removeServer(const QString &serverId)
|
||||
{
|
||||
if (serverId.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!m_serversRepository->apiV2Config(serverId).has_value()) {
|
||||
qWarning().noquote() << "SubscriptionController::removeServer: not an Api V2 server, id" << serverId;
|
||||
return false;
|
||||
}
|
||||
|
||||
const ErrorCode revokeError = deactivateDevice(serverId);
|
||||
if (revokeError != ErrorCode::NoError && revokeError != ErrorCode::ApiNotFoundError) {
|
||||
qWarning().noquote() << "SubscriptionController::removeServer: deactivateDevice failed (error"
|
||||
<< static_cast<int>(revokeError) << "); removing locally anyway.";
|
||||
}
|
||||
|
||||
m_serversRepository->removeServer(serverId);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SubscriptionController::isApiKeyExpired(const QString &serverId) const
|
||||
{
|
||||
auto apiV2 = m_serversRepository->apiV2Config(serverId);
|
||||
|
||||
@@ -74,6 +74,8 @@ public:
|
||||
|
||||
void removeApiConfig(const QString &serverId);
|
||||
|
||||
bool removeServer(const QString &serverId);
|
||||
|
||||
void setCurrentProtocol(const QString &serverId, const QString &protocolName);
|
||||
bool isVlessProtocol(const QString &serverId) const;
|
||||
|
||||
|
||||
@@ -406,6 +406,15 @@ void SubscriptionUiController::removeApiConfig(const QString &serverId)
|
||||
emit apiConfigRemoved(tr("Api config removed"));
|
||||
}
|
||||
|
||||
void SubscriptionUiController::removeServer(const QString &serverId)
|
||||
{
|
||||
const QString serverName = m_serversController->notificationDisplayName(serverId);
|
||||
if (!m_subscriptionController->removeServer(serverId)) {
|
||||
return;
|
||||
}
|
||||
emit apiServerRemoved(tr("Server '%1' was removed").arg(serverName));
|
||||
}
|
||||
|
||||
|
||||
QList<QString> SubscriptionUiController::getQrCodes()
|
||||
{
|
||||
|
||||
@@ -58,6 +58,8 @@ public slots:
|
||||
|
||||
void removeApiConfig(const QString &serverId);
|
||||
|
||||
void removeServer(const QString &serverId);
|
||||
|
||||
bool getAccountInfo(const QString &serverId, bool reload);
|
||||
void getRenewalLink(const QString &serverId);
|
||||
|
||||
@@ -78,6 +80,7 @@ signals:
|
||||
void subscriptionRefreshNeeded();
|
||||
|
||||
void apiConfigRemoved(const QString &message);
|
||||
void apiServerRemoved(const QString &message);
|
||||
|
||||
void vpnKeyExportReady();
|
||||
|
||||
|
||||
@@ -506,7 +506,7 @@ PageType {
|
||||
PageController.showNotificationMessage(qsTr("Cannot remove server during active connection"))
|
||||
} else {
|
||||
PageController.showBusyIndicator(true)
|
||||
InstallController.removeServer(ServersUiController.getServerId(ServersUiController.processedServerIndex))
|
||||
SubscriptionUiController.removeServer(ServersUiController.getServerId(ServersUiController.processedServerIndex))
|
||||
PageController.showBusyIndicator(false)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -224,6 +224,16 @@ PageType {
|
||||
PageController.showNotificationMessage(message)
|
||||
}
|
||||
|
||||
function onApiServerRemoved(message) {
|
||||
if (!ServersModel.getServersCount()) {
|
||||
PageController.goToPageHome()
|
||||
} else {
|
||||
PageController.goToStartPage()
|
||||
PageController.goToPage(PageEnum.PageSettingsServersList)
|
||||
}
|
||||
PageController.showNotificationMessage(message)
|
||||
}
|
||||
|
||||
function onInstallServerFromApiFinished(message, preferredDefaultIndex) {
|
||||
if (!ConnectionController.isConnected) {
|
||||
if (preferredDefaultIndex !== undefined && preferredDefaultIndex >= 0) {
|
||||
|
||||
Reference in New Issue
Block a user