From 6d121776a38c91a8f091917fa391e41461dabe7a Mon Sep 17 00:00:00 2001 From: MrMirDan Date: Wed, 20 May 2026 12:08:51 +0300 Subject: [PATCH] fix: config reload --- .../selfhosted/importController.cpp | 2 + client/core/controllers/serversController.cpp | 55 ++++++++++++------- client/core/controllers/serversController.h | 5 +- .../selfhosted/xraySubscriptionConfig.cpp | 4 ++ .../selfhosted/xraySubscriptionConfig.h | 1 + client/core/utils/constants/configKeys.h | 1 + client/ui/controllers/serversUiController.cpp | 19 ++++--- client/ui/controllers/serversUiController.h | 8 +-- .../qml/Pages2/PageSettingsXRayServerInfo.qml | 5 +- 9 files changed, 65 insertions(+), 35 deletions(-) diff --git a/client/core/controllers/selfhosted/importController.cpp b/client/core/controllers/selfhosted/importController.cpp index 70510ca17..cebb943e4 100644 --- a/client/core/controllers/selfhosted/importController.cpp +++ b/client/core/controllers/selfhosted/importController.cpp @@ -503,6 +503,7 @@ ImportController::ImportResult ImportController::importLink(const QUrl &url) } serverConfig.insert(configKey::description, m_appSettingsRepository->nextAvailableServerName()); + serverConfig[configKey::xraySubscriptionLink] = url.toString(); serverConfig[configKey::xraySubscriptionConfig] = configStrings; serverConfig[configKey::xraySubscriptionConfigName] = configNames; serverConfig[configKey::xraySubscriptionConfigCurrent] = 0; @@ -537,6 +538,7 @@ ImportController::ImportResult ImportController::editServerConfigWithData(const } editedConfig.insert(configKey::description, currentConfig.value(configKey::description)); + editedConfig.insert(configKey::xraySubscriptionLink, currentConfig.value(configKey::xraySubscriptionLink)); editedConfig.insert(configKey::xraySubscriptionConfig, currentConfig.value(configKey::xraySubscriptionConfig)); editedConfig.insert(configKey::xraySubscriptionConfigName, currentConfig.value(configKey::xraySubscriptionConfigName)); editedConfig.insert(configKey::xraySubscriptionConfigCurrent, currentConfig.value(configKey::xraySubscriptionConfigCurrent)); diff --git a/client/core/controllers/serversController.cpp b/client/core/controllers/serversController.cpp index bb88c2043..51be1be27 100644 --- a/client/core/controllers/serversController.cpp +++ b/client/core/controllers/serversController.cpp @@ -145,32 +145,16 @@ void ServersController::setDefaultContainer(const QString &serverId, DockerConta } } -void ServersController::setCurrentConfigIndex(const QString &serverId, const int index) +QString ServersController::getSubLink(const QString &serverId) const { const serverConfigUtils::ConfigType kind = m_serversRepository->serverKind(serverId); switch (kind) { case serverConfigUtils::ConfigType::XRaySubscription: { auto cfg = m_serversRepository->xraySubscriptionConfig(serverId); - if (!cfg.has_value()) return; - cfg->currentConfig = index; - m_serversRepository->editServer(serverId, cfg->toJson(), kind); - return; + return cfg.has_value() ? cfg->subLink : QString(); } case serverConfigUtils::ConfigType::Invalid: - default: return; - } -} - -int ServersController::getCurrentConfigIndex(const QString &serverId) const -{ - const serverConfigUtils::ConfigType kind = m_serversRepository->serverKind(serverId); - switch (kind) { - case serverConfigUtils::ConfigType::XRaySubscription: { - auto cfg = m_serversRepository->xraySubscriptionConfig(serverId); - return cfg.has_value() ? cfg->currentConfig : int(); - } - case serverConfigUtils::ConfigType::Invalid: - default: return int(); + default: return QString(); } } @@ -183,8 +167,7 @@ QString ServersController::getConfigString(const QString &serverId, const int in return cfg.has_value() ? cfg->configString.at(index).toString() : QString(); } case serverConfigUtils::ConfigType::Invalid: - default: - return QString(); + default: return QString(); } } @@ -214,6 +197,36 @@ QJsonArray ServersController::getConfigNames(const QString &serverId) const } } +int ServersController::getCurrentConfigIndex(const QString &serverId) const +{ + const serverConfigUtils::ConfigType kind = m_serversRepository->serverKind(serverId); + switch (kind) { + case serverConfigUtils::ConfigType::XRaySubscription: { + auto cfg = m_serversRepository->xraySubscriptionConfig(serverId); + return cfg.has_value() ? cfg->currentConfig : int(); + } + case serverConfigUtils::ConfigType::Invalid: + default: return int(); + } +} + +void ServersController::setCurrentConfigIndex(const QString &serverId, const int index) +{ + const serverConfigUtils::ConfigType kind = m_serversRepository->serverKind(serverId); + switch (kind) { + case serverConfigUtils::ConfigType::XRaySubscription: { + auto cfg = m_serversRepository->xraySubscriptionConfig(serverId); + if (!cfg.has_value()) + return; + cfg->currentConfig = index; + m_serversRepository->editServer(serverId, cfg->toJson(), kind); + return; + } + case serverConfigUtils::ConfigType::Invalid: + default: return; + } +} + QVector ServersController::buildServerDescriptions(bool isAmneziaDnsEnabled) const { QVector out; diff --git a/client/core/controllers/serversController.h b/client/core/controllers/serversController.h index ad751e08c..20d9c6b22 100644 --- a/client/core/controllers/serversController.h +++ b/client/core/controllers/serversController.h @@ -44,11 +44,12 @@ public: void setDefaultContainer(const QString &serverId, DockerContainer container); // XRay subscription config getters/setters - void setCurrentConfigIndex(const QString &serverId, int index); - int getCurrentConfigIndex(const QString &serverId) const; + QString getSubLink(const QString &serverId) const; QString getConfigString(const QString &serverId, const int index) const; QString getConfigName(const QString &serverId, const int index) const; QJsonArray getConfigNames(const QString &serverId) const; + int getCurrentConfigIndex(const QString &serverId) const; + void setCurrentConfigIndex(const QString &serverId, int index); // Getters QVector buildServerDescriptions(bool isAmneziaDnsEnabled) const; diff --git a/client/core/models/selfhosted/xraySubscriptionConfig.cpp b/client/core/models/selfhosted/xraySubscriptionConfig.cpp index a0897fc91..827c532d6 100644 --- a/client/core/models/selfhosted/xraySubscriptionConfig.cpp +++ b/client/core/models/selfhosted/xraySubscriptionConfig.cpp @@ -61,6 +61,9 @@ namespace amnezia obj[configKey::dns2] = dns2; } + if (!subLink.isEmpty()) { + obj[configKey::xraySubscriptionLink] = subLink; + } if (!configString.isEmpty()) { obj[configKey::xraySubscriptionConfig] = configString; } @@ -103,6 +106,7 @@ namespace amnezia config.displayName = config.description.isEmpty() ? config.hostName : config.description; } + config.subLink = json.value(configKey::xraySubscriptionLink).toString(); config.configString = json.value(configKey::xraySubscriptionConfig).toArray(); config.configName = json.value(configKey::xraySubscriptionConfigName).toArray(); config.currentConfig = json.value(configKey::xraySubscriptionConfigCurrent).toInt(); diff --git a/client/core/models/selfhosted/xraySubscriptionConfig.h b/client/core/models/selfhosted/xraySubscriptionConfig.h index fb2fc6d4f..74ffd5051 100644 --- a/client/core/models/selfhosted/xraySubscriptionConfig.h +++ b/client/core/models/selfhosted/xraySubscriptionConfig.h @@ -26,6 +26,7 @@ namespace amnezia QString dns1; QString dns2; + QString subLink; QJsonArray configString; QJsonArray configName; int currentConfig; diff --git a/client/core/utils/constants/configKeys.h b/client/core/utils/constants/configKeys.h index ae1aff954..d682f825d 100644 --- a/client/core/utils/constants/configKeys.h +++ b/client/core/utils/constants/configKeys.h @@ -33,6 +33,7 @@ namespace amnezia constexpr QLatin1String protocol("protocol"); constexpr QLatin1String protocols("protocols"); + constexpr QLatin1String xraySubscriptionLink("xray_subscription_link"); constexpr QLatin1String xraySubscriptionConfig("xray_subscription_config"); constexpr QLatin1String xraySubscriptionConfigName("xray_subscription_config_name"); constexpr QLatin1String xraySubscriptionConfigCurrent("xray_subscription_config_current"); diff --git a/client/ui/controllers/serversUiController.cpp b/client/ui/controllers/serversUiController.cpp index a02450390..5df07dce2 100644 --- a/client/ui/controllers/serversUiController.cpp +++ b/client/ui/controllers/serversUiController.cpp @@ -483,14 +483,9 @@ int ServersUiController::getServerIndexById(const QString &serverId) const return rowForServerId(m_orderedServerDescriptions, serverId); } -void ServersUiController::setCurrentConfigIndex(const int index) +QString ServersUiController::getSubLink() const { - m_serversController->setCurrentConfigIndex(m_processedServerId, index); -} - -int ServersUiController::getCurrentConfigIndex() const -{ - return m_serversController->getCurrentConfigIndex(m_processedServerId); + return m_serversController->getSubLink(m_processedServerId); } QString ServersUiController::getConfigString(const int index) const @@ -508,6 +503,16 @@ QJsonArray ServersUiController::getConfigNames() const return m_serversController->getConfigNames(m_processedServerId); } +int ServersUiController::getCurrentConfigIndex() const +{ + return m_serversController->getCurrentConfigIndex(m_processedServerId); +} + +void ServersUiController::setCurrentConfigIndex(const int index) +{ + m_serversController->setCurrentConfigIndex(m_processedServerId, index); +} + void ServersUiController::updateContainersModel() { if (m_processedServerId.isEmpty()) { diff --git a/client/ui/controllers/serversUiController.h b/client/ui/controllers/serversUiController.h index c34e01775..be60174c6 100644 --- a/client/ui/controllers/serversUiController.h +++ b/client/ui/controllers/serversUiController.h @@ -98,13 +98,13 @@ public slots: QString adHeader() const; QString adDescription() const; - void setCurrentConfigIndex(int index); - int getCurrentConfigIndex() const; + QString getSubLink() const; QString getConfigString(const int index) const; QString getConfigName(const int index) const; QJsonArray getConfigNames() const; - - + int getCurrentConfigIndex() const; + void setCurrentConfigIndex(int index); + QString getServerId(int index) const; int getServerIndexById(const QString &serverId) const; QStringList getAllInstalledServicesName(int serverIndex) const; diff --git a/client/ui/qml/Pages2/PageSettingsXRayServerInfo.qml b/client/ui/qml/Pages2/PageSettingsXRayServerInfo.qml index 6ec21ddfa..088eeea66 100644 --- a/client/ui/qml/Pages2/PageSettingsXRayServerInfo.qml +++ b/client/ui/qml/Pages2/PageSettingsXRayServerInfo.qml @@ -113,7 +113,10 @@ PageType { PageController.showNotificationMessage(qsTr("Cannot reload config during active connection")) } else { PageController.showBusyIndicator(true) - InstallController.rebootProcessedServer(ServersUiController.getProcessedServerId()) + if (!ImportController.importLink(ServersUiController.getSubLink()) && + !ImportController.editServerConfigWithData(ServersUiController.getProcessedServerId(), ServersUiController.getConfigString(ServersUiController.getCurrentConfigIndex()))) { + PageController.showNotificationMessage(qsTr("Error during config reload")) + } PageController.showBusyIndicator(false) } }