mirror of
https://github.com/amnezia-vpn/amnezia-client.git
synced 2026-06-23 02:00:20 +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.insert(configKey::description, m_appSettingsRepository->nextAvailableServerName());
|
||||||
|
serverConfig[configKey::xraySubscriptionLink] = url.toString();
|
||||||
serverConfig[configKey::xraySubscriptionConfig] = configStrings;
|
serverConfig[configKey::xraySubscriptionConfig] = configStrings;
|
||||||
serverConfig[configKey::xraySubscriptionConfigName] = configNames;
|
serverConfig[configKey::xraySubscriptionConfigName] = configNames;
|
||||||
serverConfig[configKey::xraySubscriptionConfigCurrent] = 0;
|
serverConfig[configKey::xraySubscriptionConfigCurrent] = 0;
|
||||||
@@ -537,6 +538,7 @@ ImportController::ImportResult ImportController::editServerConfigWithData(const
|
|||||||
}
|
}
|
||||||
|
|
||||||
editedConfig.insert(configKey::description, currentConfig.value(configKey::description));
|
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::xraySubscriptionConfig, currentConfig.value(configKey::xraySubscriptionConfig));
|
||||||
editedConfig.insert(configKey::xraySubscriptionConfigName, currentConfig.value(configKey::xraySubscriptionConfigName));
|
editedConfig.insert(configKey::xraySubscriptionConfigName, currentConfig.value(configKey::xraySubscriptionConfigName));
|
||||||
editedConfig.insert(configKey::xraySubscriptionConfigCurrent, currentConfig.value(configKey::xraySubscriptionConfigCurrent));
|
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);
|
const serverConfigUtils::ConfigType kind = m_serversRepository->serverKind(serverId);
|
||||||
switch (kind) {
|
switch (kind) {
|
||||||
case serverConfigUtils::ConfigType::XRaySubscription: {
|
case serverConfigUtils::ConfigType::XRaySubscription: {
|
||||||
auto cfg = m_serversRepository->xraySubscriptionConfig(serverId);
|
auto cfg = m_serversRepository->xraySubscriptionConfig(serverId);
|
||||||
if (!cfg.has_value()) return;
|
return cfg.has_value() ? cfg->subLink : QString();
|
||||||
cfg->currentConfig = index;
|
|
||||||
m_serversRepository->editServer(serverId, cfg->toJson(), kind);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
case serverConfigUtils::ConfigType::Invalid:
|
case serverConfigUtils::ConfigType::Invalid:
|
||||||
default: return;
|
default: return QString();
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -183,8 +167,7 @@ QString ServersController::getConfigString(const QString &serverId, const int in
|
|||||||
return cfg.has_value() ? cfg->configString.at(index).toString() : QString();
|
return cfg.has_value() ? cfg->configString.at(index).toString() : QString();
|
||||||
}
|
}
|
||||||
case serverConfigUtils::ConfigType::Invalid:
|
case serverConfigUtils::ConfigType::Invalid:
|
||||||
default:
|
default: return QString();
|
||||||
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> ServersController::buildServerDescriptions(bool isAmneziaDnsEnabled) const
|
||||||
{
|
{
|
||||||
QVector<ServerDescription> out;
|
QVector<ServerDescription> out;
|
||||||
|
|||||||
@@ -44,11 +44,12 @@ public:
|
|||||||
void setDefaultContainer(const QString &serverId, DockerContainer container);
|
void setDefaultContainer(const QString &serverId, DockerContainer container);
|
||||||
|
|
||||||
// XRay subscription config getters/setters
|
// XRay subscription config getters/setters
|
||||||
void setCurrentConfigIndex(const QString &serverId, int index);
|
QString getSubLink(const QString &serverId) const;
|
||||||
int getCurrentConfigIndex(const QString &serverId) const;
|
|
||||||
QString getConfigString(const QString &serverId, const int index) const;
|
QString getConfigString(const QString &serverId, const int index) const;
|
||||||
QString getConfigName(const QString &serverId, const int index) const;
|
QString getConfigName(const QString &serverId, const int index) const;
|
||||||
QJsonArray getConfigNames(const QString &serverId) const;
|
QJsonArray getConfigNames(const QString &serverId) const;
|
||||||
|
int getCurrentConfigIndex(const QString &serverId) const;
|
||||||
|
void setCurrentConfigIndex(const QString &serverId, int index);
|
||||||
|
|
||||||
// Getters
|
// Getters
|
||||||
QVector<ServerDescription> buildServerDescriptions(bool isAmneziaDnsEnabled) const;
|
QVector<ServerDescription> buildServerDescriptions(bool isAmneziaDnsEnabled) const;
|
||||||
|
|||||||
@@ -61,6 +61,9 @@ namespace amnezia
|
|||||||
obj[configKey::dns2] = dns2;
|
obj[configKey::dns2] = dns2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!subLink.isEmpty()) {
|
||||||
|
obj[configKey::xraySubscriptionLink] = subLink;
|
||||||
|
}
|
||||||
if (!configString.isEmpty()) {
|
if (!configString.isEmpty()) {
|
||||||
obj[configKey::xraySubscriptionConfig] = configString;
|
obj[configKey::xraySubscriptionConfig] = configString;
|
||||||
}
|
}
|
||||||
@@ -103,6 +106,7 @@ namespace amnezia
|
|||||||
config.displayName = config.description.isEmpty() ? config.hostName : config.description;
|
config.displayName = config.description.isEmpty() ? config.hostName : config.description;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
config.subLink = json.value(configKey::xraySubscriptionLink).toString();
|
||||||
config.configString = json.value(configKey::xraySubscriptionConfig).toArray();
|
config.configString = json.value(configKey::xraySubscriptionConfig).toArray();
|
||||||
config.configName = json.value(configKey::xraySubscriptionConfigName).toArray();
|
config.configName = json.value(configKey::xraySubscriptionConfigName).toArray();
|
||||||
config.currentConfig = json.value(configKey::xraySubscriptionConfigCurrent).toInt();
|
config.currentConfig = json.value(configKey::xraySubscriptionConfigCurrent).toInt();
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ namespace amnezia
|
|||||||
QString dns1;
|
QString dns1;
|
||||||
QString dns2;
|
QString dns2;
|
||||||
|
|
||||||
|
QString subLink;
|
||||||
QJsonArray configString;
|
QJsonArray configString;
|
||||||
QJsonArray configName;
|
QJsonArray configName;
|
||||||
int currentConfig;
|
int currentConfig;
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ namespace amnezia
|
|||||||
constexpr QLatin1String protocol("protocol");
|
constexpr QLatin1String protocol("protocol");
|
||||||
constexpr QLatin1String protocols("protocols");
|
constexpr QLatin1String protocols("protocols");
|
||||||
|
|
||||||
|
constexpr QLatin1String xraySubscriptionLink("xray_subscription_link");
|
||||||
constexpr QLatin1String xraySubscriptionConfig("xray_subscription_config");
|
constexpr QLatin1String xraySubscriptionConfig("xray_subscription_config");
|
||||||
constexpr QLatin1String xraySubscriptionConfigName("xray_subscription_config_name");
|
constexpr QLatin1String xraySubscriptionConfigName("xray_subscription_config_name");
|
||||||
constexpr QLatin1String xraySubscriptionConfigCurrent("xray_subscription_config_current");
|
constexpr QLatin1String xraySubscriptionConfigCurrent("xray_subscription_config_current");
|
||||||
|
|||||||
@@ -483,14 +483,9 @@ int ServersUiController::getServerIndexById(const QString &serverId) const
|
|||||||
return rowForServerId(m_orderedServerDescriptions, serverId);
|
return rowForServerId(m_orderedServerDescriptions, serverId);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServersUiController::setCurrentConfigIndex(const int index)
|
QString ServersUiController::getSubLink() const
|
||||||
{
|
{
|
||||||
m_serversController->setCurrentConfigIndex(m_processedServerId, index);
|
return m_serversController->getSubLink(m_processedServerId);
|
||||||
}
|
|
||||||
|
|
||||||
int ServersUiController::getCurrentConfigIndex() const
|
|
||||||
{
|
|
||||||
return m_serversController->getCurrentConfigIndex(m_processedServerId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString ServersUiController::getConfigString(const int index) const
|
QString ServersUiController::getConfigString(const int index) const
|
||||||
@@ -508,6 +503,16 @@ QJsonArray ServersUiController::getConfigNames() const
|
|||||||
return m_serversController->getConfigNames(m_processedServerId);
|
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()
|
void ServersUiController::updateContainersModel()
|
||||||
{
|
{
|
||||||
if (m_processedServerId.isEmpty()) {
|
if (m_processedServerId.isEmpty()) {
|
||||||
|
|||||||
@@ -98,12 +98,12 @@ public slots:
|
|||||||
QString adHeader() const;
|
QString adHeader() const;
|
||||||
QString adDescription() const;
|
QString adDescription() const;
|
||||||
|
|
||||||
void setCurrentConfigIndex(int index);
|
QString getSubLink() const;
|
||||||
int getCurrentConfigIndex() const;
|
|
||||||
QString getConfigString(const int index) const;
|
QString getConfigString(const int index) const;
|
||||||
QString getConfigName(const int index) const;
|
QString getConfigName(const int index) const;
|
||||||
QJsonArray getConfigNames() const;
|
QJsonArray getConfigNames() const;
|
||||||
|
int getCurrentConfigIndex() const;
|
||||||
|
void setCurrentConfigIndex(int index);
|
||||||
|
|
||||||
QString getServerId(int index) const;
|
QString getServerId(int index) const;
|
||||||
int getServerIndexById(const QString &serverId) const;
|
int getServerIndexById(const QString &serverId) const;
|
||||||
|
|||||||
@@ -113,7 +113,10 @@ PageType {
|
|||||||
PageController.showNotificationMessage(qsTr("Cannot reload config during active connection"))
|
PageController.showNotificationMessage(qsTr("Cannot reload config during active connection"))
|
||||||
} else {
|
} else {
|
||||||
PageController.showBusyIndicator(true)
|
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)
|
PageController.showBusyIndicator(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user