update model and export

This commit is contained in:
dranik
2026-03-26 11:19:12 +03:00
parent 57c6f57a12
commit 5734b3a55d
9 changed files with 60 additions and 7 deletions

View File

@@ -464,6 +464,7 @@ ProtocolConfig XrayConfigurator::createConfig(const ServerCredentials &credentia
XrayClientConfig clientConfig;
clientConfig.nativeConfig = config;
qDebug() << "config:" << config;
clientConfig.localPort = QString(amnezia::protocols::xray::defaultLocalProxyPort);
clientConfig.id = xrayClientId;

View File

@@ -201,3 +201,12 @@ bool ImportUiController::decodeQrCode(const QString &code)
return mInstance->parseQrCodeChunk(code);
}
#endif
QString ImportUiController::readTextFile(const QString &fileName)
{
QFile file(fileName);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
return {};
}
return QString::fromUtf8(file.readAll());
}

View File

@@ -28,6 +28,7 @@ public slots:
QString getMaliciousWarningText();
bool isNativeWireGuardConfig();
void processNativeWireGuardConfig();
QString readTextFile(const QString &fileName);
#if defined Q_OS_ANDROID || defined Q_OS_IOS
void startDecodingQr();

View File

@@ -114,3 +114,13 @@ void ExportUiController::applyExportResult(const ExportController::ExportResult
emit exportConfigChanged();
}
void ExportUiController::setConfigFromString(const QString &config, const QString &fileName)
{
clearPreviousConfig();
m_config = config;
emit exportConfigChanged();
if (!fileName.isEmpty()) {
SystemController::saveFile(fileName, m_config);
}
}

View File

@@ -29,6 +29,7 @@ public slots:
QList<QString> getQrCodes();
void exportConfig(const QString &fileName);
void setConfigFromString(const QString &config, const QString &fileName);
void updateClientManagementModel(int serverIndex, int containerIndex);
void revokeConfig(int row, int serverIndex, int containerIndex);

View File

@@ -193,3 +193,23 @@ QString XrayConfigsModel::buildDisplayName(const amnezia::XrayServerConfig &cfg)
return QString("%1 %2").arg(transport, security).trimmed();
}
void XrayConfigsModel::createFromXrayModel(XrayConfigModel *model)
{
if (!model) {
return;
}
createFromCurrent(model->getProtocolConfig().serverConfig);
}
void XrayConfigsModel::applyConfigToXrayModel(int index, XrayConfigModel *model)
{
if (!model) {
return;
}
amnezia::XrayServerConfig cfg = applyConfig(index);
if (cfg.port.isEmpty()) {
return; // guard against invalid index
}
model->applyServerConfig(cfg);
}

View File

@@ -9,6 +9,7 @@
#include <QVector>
#include "core/models/protocols/xrayProtocolConfig.h"
#include "ui/models/protocols/xrayConfigModel.h"
class SecureAppSettingsRepository;
@@ -49,6 +50,10 @@ public slots:
Q_INVOKABLE QString exportToJson(int index) const;
Q_INVOKABLE bool importFromJson(const QString &jsonString);
// Convenience: create snapshot from live model, apply snapshot back to model
Q_INVOKABLE void createFromXrayModel(XrayConfigModel *model);
Q_INVOKABLE void applyConfigToXrayModel(int index, XrayConfigModel *model);
signals:
void configApplied(int index);
void configRemoved(int index);

View File

@@ -58,7 +58,7 @@ PageType {
textMaximumLineCount: 2
rightImageSource: "qrc:/images/controls/chevron-right.svg"
clickedFunction: function() {
XrayConfigsModel.createFromCurrent(XrayConfigModel.getProtocolConfig().serverConfig)
XrayConfigsModel.createFromXrayModel(XrayConfigModel)
}
}
@@ -72,11 +72,11 @@ PageType {
clickedFunction: function() {
if (root.selectedConfigIndex >= 0) {
var json = XrayConfigsModel.exportToJson(root.selectedConfigIndex)
ExportController.shareText(json, "xray_config.json")
ExportController.setConfigFromString(json, "xray_config.json")
} else if (XrayConfigsModel.rowCount() > 0) {
// Export the first one if none selected
var json = XrayConfigsModel.exportToJson(0)
ExportController.shareText(json, "xray_config.json")
ExportController.setConfigFromString(json, "xray_config.json")
}
}
}
@@ -90,7 +90,13 @@ PageType {
descriptionText: qsTr("In JSON format")
rightImageSource: "qrc:/images/controls/chevron-right.svg"
clickedFunction: function() {
ImportController.importConfig()
var filePath = SystemController.getFileName(qsTr("Open XRay config"), qsTr("JSON files (*.json)"))
if (filePath !== "") {
var jsonContent = ImportController.readTextFile(filePath)
if (jsonContent !== "") {
XrayConfigsModel.importFromJson(jsonContent)
}
}
}
}
@@ -200,8 +206,7 @@ PageType {
rightImageSource: "qrc:/images/controls/chevron-right.svg"
clickedFunction: function() {
configActionsDrawer.closeTriggered()
var serverConfig = XrayConfigsModel.applyConfig(root.selectedConfigIndex)
XrayConfigModel.applyServerConfig(serverConfig)
XrayConfigsModel.applyConfigToXrayModel(root.selectedConfigIndex, XrayConfigModel)
PageController.closePage()
}
}
@@ -216,7 +221,7 @@ PageType {
clickedFunction: function() {
configActionsDrawer.closeTriggered()
var json = XrayConfigsModel.exportToJson(root.selectedConfigIndex)
ExportController.shareText(json, "xray_config.json")
ExportController.setConfigFromString(json, "xray_config.json")
}
}

View File

@@ -84,6 +84,7 @@
<file>Pages2/PageProtocolXrayTransportSettings.qml</file>
<file>Pages2/PageProtocolXrayXmuxSettings.qml</file>
<file>Pages2/PageProtocolXrayXPaddingSettings.qml</file>
<file>Pages2/PageProtocolXrayXPaddingBytesSettings.qml</file>
<file>Controls2/MinMaxRowType.qml</file>
<file>Pages2/PageServiceDnsSettings.qml</file>