feat: added a temporary switch for the xray protocol on api settings page
This commit is contained in:
parent
005cb164a5
commit
ab340c3257
3 changed files with 58 additions and 2 deletions
|
@ -18,7 +18,7 @@ namespace
|
|||
{
|
||||
constexpr char cloak[] = "cloak";
|
||||
constexpr char awg[] = "awg";
|
||||
constexpr char xray[] = "xray";
|
||||
constexpr char vless[] = "vless";
|
||||
|
||||
constexpr char apiEndpoint[] = "api_endpoint";
|
||||
constexpr char accessToken[] = "api_key";
|
||||
|
@ -109,7 +109,7 @@ namespace
|
|||
auto connData = WireguardConfigurator::genClientKeys();
|
||||
protocolData.wireGuardClientPubKey = connData.clientPubKey;
|
||||
protocolData.wireGuardClientPrivKey = connData.clientPrivKey;
|
||||
} else if (protocol == configKey::xray) {
|
||||
} else if (protocol == configKey::vless) {
|
||||
protocolData.xrayUuid = QUuid::createUuid().toString(QUuid::WithoutBraces);
|
||||
}
|
||||
|
||||
|
@ -122,6 +122,8 @@ namespace
|
|||
apiPayload[configKey::certificate] = protocolData.certRequest.request;
|
||||
} else if (protocol == configKey::awg) {
|
||||
apiPayload[configKey::publicKey] = protocolData.wireGuardClientPubKey;
|
||||
} else if (protocol == configKey::vless) {
|
||||
apiPayload[configKey::publicKey] = protocolData.xrayUuid;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -201,6 +203,8 @@ namespace
|
|||
|
||||
serverConfig[configKey::apiConfig] = apiConfig;
|
||||
|
||||
qDebug() << serverConfig;
|
||||
|
||||
return ErrorCode::NoError;
|
||||
}
|
||||
}
|
||||
|
@ -563,6 +567,31 @@ bool ApiConfigsController::isConfigValid()
|
|||
return true;
|
||||
}
|
||||
|
||||
void ApiConfigsController::setCurrentProtocol(const QString &protocolName)
|
||||
{
|
||||
auto serverIndex = m_serversModel->getProcessedServerIndex();
|
||||
auto serverConfigObject = m_serversModel->getServerConfig(serverIndex);
|
||||
auto apiConfigObject = serverConfigObject.value(configKey::apiConfig).toObject();
|
||||
|
||||
apiConfigObject[configKey::serviceProtocol] = protocolName;
|
||||
|
||||
serverConfigObject.insert(configKey::apiConfig, apiConfigObject);
|
||||
|
||||
m_serversModel->editServer(serverConfigObject, serverIndex);
|
||||
}
|
||||
|
||||
bool ApiConfigsController::isVlessProtocol()
|
||||
{
|
||||
auto serverIndex = m_serversModel->getProcessedServerIndex();
|
||||
auto serverConfigObject = m_serversModel->getServerConfig(serverIndex);
|
||||
auto apiConfigObject = serverConfigObject.value(configKey::apiConfig).toObject();
|
||||
|
||||
if (apiConfigObject[configKey::serviceProtocol].toString() == "vless") {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
QList<QString> ApiConfigsController::getQrCodes()
|
||||
{
|
||||
return m_qrCodes;
|
||||
|
|
|
@ -35,6 +35,9 @@ public slots:
|
|||
|
||||
bool isConfigValid();
|
||||
|
||||
void setCurrentProtocol(const QString &protocolName);
|
||||
bool isVlessProtocol();
|
||||
|
||||
signals:
|
||||
void errorOccurred(ErrorCode errorCode);
|
||||
|
||||
|
|
|
@ -158,6 +158,30 @@ PageType {
|
|||
|
||||
readonly property bool isVisibleForAmneziaFree: ApiAccountInfoModel.data("isComponentVisible")
|
||||
|
||||
SwitcherType {
|
||||
id: switcher
|
||||
|
||||
readonly property bool isVlessProtocol: ApiConfigsController.isVlessProtocol()
|
||||
|
||||
Layout.fillWidth: true
|
||||
Layout.topMargin: 24
|
||||
Layout.rightMargin: 16
|
||||
Layout.leftMargin: 16
|
||||
|
||||
text: qsTr("Use VLESS protocol")
|
||||
checked: switcher.isVlessProtocol
|
||||
onToggled: function() {
|
||||
if (ServersModel.isDefaultServerCurrentlyProcessed() && ConnectionController.isConnected) {
|
||||
PageController.showNotificationMessage(qsTr("Cannot change protocol during active connection"))
|
||||
} else {
|
||||
PageController.showBusyIndicator(true)
|
||||
ApiConfigsController.setCurrentProtocol(switcher.isVlessProtocol ? "awg" : "vless")
|
||||
ApiConfigsController.updateServiceFromGateway(ServersModel.processedIndex, "", "", true)
|
||||
PageController.showBusyIndicator(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
WarningType {
|
||||
id: warning
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue