refactoring: moved IsProtocolSelectionSupported to apiAccountInfoModel
This commit is contained in:
parent
98c4389445
commit
7e3aa443a2
6 changed files with 19 additions and 18 deletions
|
|
@ -32,6 +32,7 @@ namespace apiDefs
|
||||||
constexpr QLatin1String stackType("stack_type");
|
constexpr QLatin1String stackType("stack_type");
|
||||||
constexpr QLatin1String serviceType("service_type");
|
constexpr QLatin1String serviceType("service_type");
|
||||||
constexpr QLatin1String cliVersion("cli_version");
|
constexpr QLatin1String cliVersion("cli_version");
|
||||||
|
constexpr QLatin1String supportedProtocols("supported_protocols");
|
||||||
|
|
||||||
constexpr QLatin1String vpnKey("vpn_key");
|
constexpr QLatin1String vpnKey("vpn_key");
|
||||||
constexpr QLatin1String config("config");
|
constexpr QLatin1String config("config");
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,6 @@ namespace
|
||||||
constexpr char serviceType[] = "service_type";
|
constexpr char serviceType[] = "service_type";
|
||||||
constexpr char serviceInfo[] = "service_info";
|
constexpr char serviceInfo[] = "service_info";
|
||||||
constexpr char serviceProtocol[] = "service_protocol";
|
constexpr char serviceProtocol[] = "service_protocol";
|
||||||
constexpr char supportedProtocols[] = "supported_protocols";
|
|
||||||
|
|
||||||
constexpr char apiPayload[] = "api_payload";
|
constexpr char apiPayload[] = "api_payload";
|
||||||
constexpr char keyPayload[] = "key_payload";
|
constexpr char keyPayload[] = "key_payload";
|
||||||
|
|
@ -198,8 +197,8 @@ namespace
|
||||||
auto apiConfig = QJsonObject::fromVariantMap(map);
|
auto apiConfig = QJsonObject::fromVariantMap(map);
|
||||||
|
|
||||||
if (newServerConfig.value(config_key::configVersion).toInt() == apiDefs::ConfigSource::AmneziaGateway) {
|
if (newServerConfig.value(config_key::configVersion).toInt() == apiDefs::ConfigSource::AmneziaGateway) {
|
||||||
apiConfig.insert(configKey::supportedProtocols,
|
apiConfig.insert(apiDefs::key::supportedProtocols,
|
||||||
QJsonDocument::fromJson(apiResponseBody).object().value(configKey::supportedProtocols).toArray());
|
QJsonDocument::fromJson(apiResponseBody).object().value(apiDefs::key::supportedProtocols).toArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
serverConfig[configKey::apiConfig] = apiConfig;
|
serverConfig[configKey::apiConfig] = apiConfig;
|
||||||
|
|
@ -593,18 +592,6 @@ bool ApiConfigsController::isVlessProtocol()
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ApiConfigsController::isProtocolSelectionSupported()
|
|
||||||
{
|
|
||||||
auto serverIndex = m_serversModel->getProcessedServerIndex();
|
|
||||||
auto serverConfigObject = m_serversModel->getServerConfig(serverIndex);
|
|
||||||
auto apiConfigObject = serverConfigObject.value(configKey::apiConfig).toObject();
|
|
||||||
|
|
||||||
if (apiConfigObject[configKey::supportedProtocols].toArray().isEmpty()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
QList<QString> ApiConfigsController::getQrCodes()
|
QList<QString> ApiConfigsController::getQrCodes()
|
||||||
{
|
{
|
||||||
return m_qrCodes;
|
return m_qrCodes;
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,6 @@ public slots:
|
||||||
|
|
||||||
void setCurrentProtocol(const QString &protocolName);
|
void setCurrentProtocol(const QString &protocolName);
|
||||||
bool isVlessProtocol();
|
bool isVlessProtocol();
|
||||||
bool isProtocolSelectionSupported();
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void errorOccurred(ErrorCode errorCode);
|
void errorOccurred(ErrorCode errorCode);
|
||||||
|
|
|
||||||
|
|
@ -75,6 +75,12 @@ QVariant ApiAccountInfoModel::data(const QModelIndex &index, int role) const
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
case IsProtocolSelectionSupportedRole: {
|
||||||
|
if (m_accountInfoData.supportedProtocols.size() > 1) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
|
@ -95,6 +101,10 @@ void ApiAccountInfoModel::updateModel(const QJsonObject &accountInfoObject, cons
|
||||||
|
|
||||||
accountInfoData.configType = apiUtils::getConfigType(serverConfig);
|
accountInfoData.configType = apiUtils::getConfigType(serverConfig);
|
||||||
|
|
||||||
|
for (const auto &protocol : accountInfoObject.value(apiDefs::key::supportedProtocols).toArray()) {
|
||||||
|
accountInfoData.supportedProtocols.push_back(protocol.toString());
|
||||||
|
}
|
||||||
|
|
||||||
m_accountInfoData = accountInfoData;
|
m_accountInfoData = accountInfoData;
|
||||||
|
|
||||||
m_supportInfo = accountInfoObject.value(apiDefs::key::supportInfo).toObject();
|
m_supportInfo = accountInfoObject.value(apiDefs::key::supportInfo).toObject();
|
||||||
|
|
@ -159,6 +169,7 @@ QHash<int, QByteArray> ApiAccountInfoModel::roleNames() const
|
||||||
roles[ServiceDescriptionRole] = "serviceDescription";
|
roles[ServiceDescriptionRole] = "serviceDescription";
|
||||||
roles[IsComponentVisibleRole] = "isComponentVisible";
|
roles[IsComponentVisibleRole] = "isComponentVisible";
|
||||||
roles[HasExpiredWorkerRole] = "hasExpiredWorker";
|
roles[HasExpiredWorkerRole] = "hasExpiredWorker";
|
||||||
|
roles[IsProtocolSelectionSupportedRole] = "isProtocolSelectionSupported";
|
||||||
|
|
||||||
return roles;
|
return roles;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,8 @@ public:
|
||||||
ServiceDescriptionRole,
|
ServiceDescriptionRole,
|
||||||
EndDateRole,
|
EndDateRole,
|
||||||
IsComponentVisibleRole,
|
IsComponentVisibleRole,
|
||||||
HasExpiredWorkerRole
|
HasExpiredWorkerRole,
|
||||||
|
IsProtocolSelectionSupportedRole
|
||||||
};
|
};
|
||||||
|
|
||||||
explicit ApiAccountInfoModel(QObject *parent = nullptr);
|
explicit ApiAccountInfoModel(QObject *parent = nullptr);
|
||||||
|
|
@ -51,6 +52,8 @@ private:
|
||||||
int maxDeviceCount;
|
int maxDeviceCount;
|
||||||
|
|
||||||
apiDefs::ConfigType configType;
|
apiDefs::ConfigType configType;
|
||||||
|
|
||||||
|
QStringList supportedProtocols;
|
||||||
};
|
};
|
||||||
|
|
||||||
AccountInfoData m_accountInfoData;
|
AccountInfoData m_accountInfoData;
|
||||||
|
|
|
||||||
|
|
@ -168,7 +168,7 @@ PageType {
|
||||||
Layout.rightMargin: 16
|
Layout.rightMargin: 16
|
||||||
Layout.leftMargin: 16
|
Layout.leftMargin: 16
|
||||||
|
|
||||||
visible: ApiConfigsController.isProtocolSelectionSupported()
|
visible: ApiAccountInfoModel.data("isProtocolSelectionSupported")
|
||||||
|
|
||||||
text: qsTr("Use VLESS protocol")
|
text: qsTr("Use VLESS protocol")
|
||||||
checked: switcher.isVlessProtocol
|
checked: switcher.isVlessProtocol
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue