mirror of
https://github.com/amnezia-vpn/amnezia-client.git
synced 2026-06-23 02:00:20 +07:00
chore: minor fixes
This commit is contained in:
@@ -37,8 +37,6 @@ namespace
|
|||||||
|
|
||||||
constexpr char isAvailable[] = "is_available";
|
constexpr char isAvailable[] = "is_available";
|
||||||
|
|
||||||
constexpr char supportInfo[] = "support_info";
|
|
||||||
|
|
||||||
constexpr char subscriptionPlans[] = "subscription_plans";
|
constexpr char subscriptionPlans[] = "subscription_plans";
|
||||||
constexpr char benefits[] = "benefits";
|
constexpr char benefits[] = "benefits";
|
||||||
}
|
}
|
||||||
@@ -176,8 +174,8 @@ QVariant ApiServicesModel::data(const QModelIndex &index, int role) const
|
|||||||
case SubscriptionPlansRole: {
|
case SubscriptionPlansRole: {
|
||||||
return apiServiceData.subscriptionPlans;
|
return apiServiceData.subscriptionPlans;
|
||||||
}
|
}
|
||||||
case BenefitPanelRowsRole: {
|
case BenefitRowsRole: {
|
||||||
return buildBenefitPanelRows(apiServiceData);
|
return buildBenefitRows(apiServiceData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -306,7 +304,7 @@ QHash<int, QByteArray> ApiServicesModel::roleNames() const
|
|||||||
roles[EndDateRole] = "endDate";
|
roles[EndDateRole] = "endDate";
|
||||||
roles[OrderRole] = "order";
|
roles[OrderRole] = "order";
|
||||||
roles[SubscriptionPlansRole] = "subscriptionPlans";
|
roles[SubscriptionPlansRole] = "subscriptionPlans";
|
||||||
roles[BenefitPanelRowsRole] = "benefitRows";
|
roles[BenefitRowsRole] = "benefitRows";
|
||||||
|
|
||||||
return roles;
|
return roles;
|
||||||
}
|
}
|
||||||
@@ -333,9 +331,9 @@ ApiServicesModel::ApiServicesData ApiServicesModel::getApiServicesData(const QJs
|
|||||||
serviceData.serviceInfo.features = serviceDescription.value(configKey::features).toString();
|
serviceData.serviceInfo.features = serviceDescription.value(configKey::features).toString();
|
||||||
|
|
||||||
serviceData.subscriptionPlans = jsonObjectArrayToVariantList(serviceDescription.value(configKey::subscriptionPlans).toArray());
|
serviceData.subscriptionPlans = jsonObjectArrayToVariantList(serviceDescription.value(configKey::subscriptionPlans).toArray());
|
||||||
serviceData.benefitsConfig = serviceDescription.value(configKey::benefits).toArray();
|
serviceData.benefits = serviceDescription.value(configKey::benefits).toArray();
|
||||||
|
|
||||||
serviceData.supportInfo = data.value(configKey::supportInfo).toObject();
|
serviceData.supportInfo = data.value(apiDefs::key::supportInfo).toObject();
|
||||||
|
|
||||||
serviceData.type = serviceType;
|
serviceData.type = serviceType;
|
||||||
serviceData.protocol = serviceProtocol;
|
serviceData.protocol = serviceProtocol;
|
||||||
@@ -381,8 +379,8 @@ QString ApiServicesModel::benefitInjectValue(const QString &injectKey, const Ser
|
|||||||
return formatPriceForBenefit(info.price);
|
return formatPriceForBenefit(info.price);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (injectKey == QLatin1String("support_telegram")) {
|
if (injectKey == apiDefs::key::telegram) {
|
||||||
const QString handle = supportInfo.value(QStringLiteral("telegram")).toString().trimmed();
|
const QString handle = supportInfo.value(apiDefs::key::telegram).toString().trimmed();
|
||||||
if (handle.isEmpty()) {
|
if (handle.isEmpty()) {
|
||||||
return QStringLiteral("—");
|
return QStringLiteral("—");
|
||||||
}
|
}
|
||||||
@@ -394,10 +392,10 @@ QString ApiServicesModel::benefitInjectValue(const QString &injectKey, const Ser
|
|||||||
return QString();
|
return QString();
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariantList ApiServicesModel::buildBenefitPanelRows(const ApiServicesData &service) const
|
QVariantList ApiServicesModel::buildBenefitRows(const ApiServicesData &service) const
|
||||||
{
|
{
|
||||||
QVariantList out;
|
QVariantList out;
|
||||||
for (const QJsonValue &v : service.benefitsConfig) {
|
for (const QJsonValue &v : service.benefits) {
|
||||||
if (!v.isObject()) {
|
if (!v.isObject()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -420,8 +418,8 @@ QVariantList ApiServicesModel::buildBenefitPanelRows(const ApiServicesData &serv
|
|||||||
m.insert(QStringLiteral("icon"), iconUrlFromGatewayBenefitIcon(iconKey));
|
m.insert(QStringLiteral("icon"), iconUrlFromGatewayBenefitIcon(iconKey));
|
||||||
m.insert(QStringLiteral("title"), title);
|
m.insert(QStringLiteral("title"), title);
|
||||||
m.insert(QStringLiteral("body"), body);
|
m.insert(QStringLiteral("body"), body);
|
||||||
if (o.value(QStringLiteral("body_accent")).toBool()) {
|
if (o.value(QStringLiteral("accent")).toBool()) {
|
||||||
m.insert(QStringLiteral("body_accent"), true);
|
m.insert(QStringLiteral("accent"), true);
|
||||||
}
|
}
|
||||||
out.append(m);
|
out.append(m);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ public:
|
|||||||
EndDateRole,
|
EndDateRole,
|
||||||
OrderRole,
|
OrderRole,
|
||||||
SubscriptionPlansRole,
|
SubscriptionPlansRole,
|
||||||
BenefitPanelRowsRole
|
BenefitRowsRole
|
||||||
};
|
};
|
||||||
|
|
||||||
explicit ApiServicesModel(QObject *parent = nullptr);
|
explicit ApiServicesModel(QObject *parent = nullptr);
|
||||||
@@ -92,12 +92,12 @@ private:
|
|||||||
QJsonArray availableCountries;
|
QJsonArray availableCountries;
|
||||||
|
|
||||||
QVariantList subscriptionPlans;
|
QVariantList subscriptionPlans;
|
||||||
QJsonArray benefitsConfig;
|
QJsonArray benefits;
|
||||||
};
|
};
|
||||||
|
|
||||||
ApiServicesData getApiServicesData(const QJsonObject &data);
|
ApiServicesData getApiServicesData(const QJsonObject &data);
|
||||||
|
|
||||||
QVariantList buildBenefitPanelRows(const ApiServicesData &service) const;
|
QVariantList buildBenefitRows(const ApiServicesData &service) const;
|
||||||
QString benefitInjectValue(const QString &injectKey, const ServiceInfo &info,
|
QString benefitInjectValue(const QString &injectKey, const ServiceInfo &info,
|
||||||
const QJsonObject &supportInfo) const;
|
const QJsonObject &supportInfo) const;
|
||||||
QString formatPriceForBenefit(const QString &rawPrice) const;
|
QString formatPriceForBenefit(const QString &rawPrice) const;
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ RowLayout {
|
|||||||
property string iconSource: ""
|
property string iconSource: ""
|
||||||
property string titleText: ""
|
property string titleText: ""
|
||||||
property string bodyText: ""
|
property string bodyText: ""
|
||||||
property bool bodyAccent: false
|
property bool accent: false
|
||||||
|
|
||||||
spacing: 12
|
spacing: 12
|
||||||
|
|
||||||
@@ -44,14 +44,14 @@ RowLayout {
|
|||||||
id: bodyLabel
|
id: bodyLabel
|
||||||
width: parent.width
|
width: parent.width
|
||||||
text: root.bodyText
|
text: root.bodyText
|
||||||
color: root.bodyAccent ? AmneziaStyle.color.goldenApricot : AmneziaStyle.color.mutedGray
|
color: root.accent ? AmneziaStyle.color.goldenApricot : AmneziaStyle.color.mutedGray
|
||||||
font.pixelSize: 14
|
font.pixelSize: 14
|
||||||
wrapMode: Text.Wrap
|
wrapMode: Text.Wrap
|
||||||
}
|
}
|
||||||
|
|
||||||
MouseArea {
|
MouseArea {
|
||||||
anchors.fill: bodyLabel
|
anchors.fill: bodyLabel
|
||||||
visible: root.bodyAccent && root.bodyText.length > 0
|
visible: root.accent && root.bodyText.length > 0
|
||||||
cursorShape: Qt.PointingHandCursor
|
cursorShape: Qt.PointingHandCursor
|
||||||
onClicked: {
|
onClicked: {
|
||||||
var t = root.bodyText.trim()
|
var t = root.bodyText.trim()
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ Rectangle {
|
|||||||
iconSource: root.benefitItems[index].icon
|
iconSource: root.benefitItems[index].icon
|
||||||
titleText: root.benefitItems[index].title
|
titleText: root.benefitItems[index].title
|
||||||
bodyText: root.benefitItems[index].body
|
bodyText: root.benefitItems[index].body
|
||||||
bodyAccent: !!root.benefitItems[index].body_accent
|
accent: !!root.benefitItems[index].accent
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,31 +13,28 @@ import "../Components"
|
|||||||
PageType {
|
PageType {
|
||||||
id: root
|
id: root
|
||||||
|
|
||||||
// ApiServicesModel selection is amnezia-premium (set in PageSetupWizardApiServicesList before navigation).
|
|
||||||
|
|
||||||
property var subscriptionPlans: []
|
property var subscriptionPlans: []
|
||||||
property var benefitRows: []
|
property var benefitRows: []
|
||||||
property int selectedGatewayPlanIndex: 0
|
property int selectedPlanIndex: 0
|
||||||
property string premiumFeaturesHtml: ""
|
property string premiumFeaturesHtml: ""
|
||||||
property string premiumHeaderName: ""
|
property string premiumHeaderName: ""
|
||||||
property string premiumHeaderDescription: ""
|
property string premiumHeaderDescription: ""
|
||||||
|
|
||||||
readonly property var currentGatewayPlan: subscriptionPlans[selectedGatewayPlanIndex]
|
readonly property var currentPlan: subscriptionPlans[selectedPlanIndex]
|
||||||
|
|
||||||
function syncFromModel() {
|
function syncFromModel() {
|
||||||
root.subscriptionPlans = ApiServicesModel.getSelectedServiceData("subscriptionPlans")
|
root.subscriptionPlans = ApiServicesModel.getSelectedServiceData("subscriptionPlans")
|
||||||
root.benefitRows = ApiServicesModel.getSelectedServiceData("benefitRows")
|
root.benefitRows = ApiServicesModel.getSelectedServiceData("benefitRows")
|
||||||
|
|
||||||
root.selectedGatewayPlanIndex = 0
|
root.selectedPlanIndex = 0
|
||||||
for (var i = 0; i < root.subscriptionPlans.length; ++i) {
|
for (var i = 0; i < root.subscriptionPlans.length; ++i) {
|
||||||
if (root.subscriptionPlans[i].recommended) {
|
if (root.subscriptionPlans[i].recommended) {
|
||||||
root.selectedGatewayPlanIndex = i
|
root.selectedPlanIndex = i
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
root.premiumFeaturesHtml = String(ApiServicesModel.getSelectedServiceData("features")).replace("%1",
|
root.premiumFeaturesHtml = String(ApiServicesModel.getSelectedServiceData("features")).replace("%1", LanguageModel.getCurrentSiteUrl("free")).replace("/free", "")
|
||||||
LanguageModel.getCurrentSiteUrl("free")).replace("/free", "")
|
|
||||||
root.premiumHeaderName = String(ApiServicesModel.getSelectedServiceData("name"))
|
root.premiumHeaderName = String(ApiServicesModel.getSelectedServiceData("name"))
|
||||||
root.premiumHeaderDescription = String(ApiServicesModel.getSelectedServiceData("serviceDescription"))
|
root.premiumHeaderDescription = String(ApiServicesModel.getSelectedServiceData("serviceDescription"))
|
||||||
}
|
}
|
||||||
@@ -118,14 +115,14 @@ PageType {
|
|||||||
Layout.rightMargin: 16
|
Layout.rightMargin: 16
|
||||||
Layout.bottomMargin: index === root.subscriptionPlans.length - 1 ? 24 : 12
|
Layout.bottomMargin: index === root.subscriptionPlans.length - 1 ? 24 : 12
|
||||||
|
|
||||||
selected: root.selectedGatewayPlanIndex === index
|
selected: root.selectedPlanIndex === index
|
||||||
primaryLeft: String(plan.primary_left)
|
primaryLeft: String(plan.primary_left)
|
||||||
primaryRight: String(plan.primary_right)
|
primaryRight: String(plan.primary_right)
|
||||||
subtitle: String(plan.subtitle)
|
subtitle: String(plan.subtitle)
|
||||||
showRecommendedBadge: !!plan.recommended
|
showRecommendedBadge: !!plan.recommended
|
||||||
recommendedText: qsTr("Recommended")
|
recommendedText: qsTr("Recommended")
|
||||||
|
|
||||||
onSelectRequested: root.selectedGatewayPlanIndex = index
|
onSelectRequested: root.selectedPlanIndex = index
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -258,7 +255,7 @@ PageType {
|
|||||||
anchors.bottomMargin: 16 + SettingsController.safeAreaBottomMargin
|
anchors.bottomMargin: 16 + SettingsController.safeAreaBottomMargin
|
||||||
|
|
||||||
text: {
|
text: {
|
||||||
var plan = root.currentGatewayPlan
|
var plan = root.currentPlan
|
||||||
if (!plan) {
|
if (!plan) {
|
||||||
return qsTr("Continue")
|
return qsTr("Continue")
|
||||||
}
|
}
|
||||||
@@ -266,7 +263,7 @@ PageType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
clickedFunc: function() {
|
clickedFunc: function() {
|
||||||
var plan = root.currentGatewayPlan
|
var plan = root.currentPlan
|
||||||
if (!plan) {
|
if (!plan) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user