refactor: deactivate api config before remove (#2569)

Co-authored-by: vkamn <vk@amnezia.org>
This commit is contained in:
yp
2026-05-15 09:56:09 +03:00
committed by GitHub
parent fd0c773918
commit d0a1af0381
6 changed files with 46 additions and 1 deletions

View File

@@ -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);

View File

@@ -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;

View File

@@ -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()
{

View File

@@ -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();

View File

@@ -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)
}
}

View File

@@ -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) {