mirror of
https://github.com/amnezia-vpn/amnezia-client.git
synced 2026-06-22 02:01:08 +07:00
fix: config reload
This commit is contained in:
@@ -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));
|
||||
|
||||
@@ -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<ServerDescription> ServersController::buildServerDescriptions(bool isAmneziaDnsEnabled) const
|
||||
{
|
||||
QVector<ServerDescription> out;
|
||||
|
||||
@@ -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<ServerDescription> buildServerDescriptions(bool isAmneziaDnsEnabled) const;
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -26,6 +26,7 @@ namespace amnezia
|
||||
QString dns1;
|
||||
QString dns2;
|
||||
|
||||
QString subLink;
|
||||
QJsonArray configString;
|
||||
QJsonArray configName;
|
||||
int currentConfig;
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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()) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user