mirror of
https://github.com/amnezia-vpn/amnezia-client.git
synced 2026-05-08 14:33:23 +00:00
update: configs from list can be choosen
This commit is contained in:
@@ -117,6 +117,7 @@ bool ImportController::importLink(const QUrl &url)
|
||||
for (const QString &cfg : configs) {
|
||||
if (cfg.startsWith("vless://") || cfg.startsWith("vmess://") || cfg.startsWith("trojan://")
|
||||
|| cfg.startsWith("ss://") || cfg.startsWith("ssd://")) {
|
||||
// TODO: fix config_key::description for some configs
|
||||
extractConfigFromData(cfg);
|
||||
obj["config_name"] = m_config.value(config_key::description);
|
||||
qDebug() << m_config.value(config_key::description);
|
||||
@@ -134,7 +135,7 @@ bool ImportController::importLink(const QUrl &url)
|
||||
serverConfig.insert(it.key(), it.value());
|
||||
}
|
||||
// TODO: proper name instead of XRaySubLink Test
|
||||
serverConfig.insert("description", "XRaySubLink Test");
|
||||
serverConfig.insert(config_key::description, "XRaySubLink Test");
|
||||
serverConfig.insert("xray_subscription_config", configsArray);
|
||||
serverConfig.insert("xray_subscription_config_current", 0);
|
||||
|
||||
@@ -148,6 +149,32 @@ bool ImportController::importLink(const QUrl &url)
|
||||
return true;
|
||||
}
|
||||
|
||||
// TODO: remove configIndex and fix bug with "xray_subscription_config_current" value saving
|
||||
bool ImportController::editServerConfigWithData(QString data, int serverIndex, int configIndex)
|
||||
{
|
||||
m_maliciousWarningText.clear();
|
||||
|
||||
extractConfigFromData(data);
|
||||
|
||||
QJsonObject serverCurrentConfig = m_serversModel->getServerConfig(serverIndex);
|
||||
QJsonObject serverConfig;
|
||||
|
||||
for (auto it = m_config.begin(); it != m_config.end(); ++it) {
|
||||
serverConfig.insert(it.key(), it.value());
|
||||
}
|
||||
serverConfig.insert(config_key::description, serverCurrentConfig.value(config_key::description));
|
||||
serverConfig.insert("xray_subscription_config", serverCurrentConfig.value("xray_subscription_config"));
|
||||
serverConfig.insert("xray_subscription_config_current", configIndex);
|
||||
|
||||
m_serversModel->editServer(serverConfig, serverIndex);
|
||||
|
||||
m_config = {};
|
||||
m_configFileName.clear();
|
||||
m_maliciousWarningText.clear();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ImportController::isValidBase64(const QByteArray &input)
|
||||
{
|
||||
QByteArray data = input;
|
||||
|
||||
@@ -34,6 +34,7 @@ public slots:
|
||||
bool importLink(const QUrl &url);
|
||||
bool isValidBase64(const QByteArray &input);
|
||||
QByteArray base64Decode(const QByteArray &input);
|
||||
bool editServerConfigWithData(QString data, int serverIndex, int configIndex);
|
||||
bool extractConfigFromFile(const QString &fileName);
|
||||
bool extractConfigFromData(QString data);
|
||||
bool extractConfigFromQr(const QByteArray &data);
|
||||
|
||||
@@ -372,6 +372,13 @@ const QJsonArray ServersModel::getConfigNames()
|
||||
return configsNamesArray;
|
||||
}
|
||||
|
||||
const QString ServersModel::getConfigString(const int &index)
|
||||
{
|
||||
const QJsonObject server = m_servers.at(m_defaultServerIndex).toObject();
|
||||
QJsonArray configsArray = server.value(configKey::xraySubscriptionConfig).toArray();
|
||||
return configsArray.at(index).toObject().value(configKey::xraySubscriptionConfigString).toString();
|
||||
}
|
||||
|
||||
bool ServersModel::isDefaultServerCurrentlyProcessed()
|
||||
{
|
||||
return m_defaultServerIndex == m_processedServerIndex;
|
||||
|
||||
@@ -120,6 +120,7 @@ public slots:
|
||||
void setCurrentConfigIndex(const int &index);
|
||||
const QString getConfigName(const int &index);
|
||||
const QJsonArray getConfigNames();
|
||||
const QString getConfigString(const int &index);
|
||||
|
||||
void addServer(const QJsonObject &server);
|
||||
void editServer(const QJsonObject &server, const int serverIndex);
|
||||
|
||||
@@ -123,8 +123,8 @@ PageType {
|
||||
|
||||
if (index !== ServersModel.getCurrentConfigIndex()) {
|
||||
PageController.showBusyIndicator(true)
|
||||
var prevIndex = ServersModel.getCurrentConfigIndex()
|
||||
ServersModel.setCurrentConfigIndex(index)
|
||||
ImportController.editServerConfigWithData(ServersModel.getConfigString(index), ServersModel.getProcessedServerIndex(), index)
|
||||
PageController.showBusyIndicator(false)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user