From a5254ac238a6d1293191165f9fea0bfeb7f91104 Mon Sep 17 00:00:00 2001 From: "vladimir.kuznetsov" Date: Wed, 19 Feb 2025 14:56:53 +0700 Subject: [PATCH] chore: fixed qr code display --- .../controllers/api/apiConfigsController.cpp | 4 ++-- .../qml/Components/ShareConnectionDrawer.qml | 23 +++++++++++-------- .../qml/Pages2/PageSettingsApiServerInfo.qml | 2 +- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/client/ui/controllers/api/apiConfigsController.cpp b/client/ui/controllers/api/apiConfigsController.cpp index 33894e79..0861471a 100644 --- a/client/ui/controllers/api/apiConfigsController.cpp +++ b/client/ui/controllers/api/apiConfigsController.cpp @@ -99,8 +99,7 @@ void ApiConfigsController::prepareVpnKeyExport() auto vpnKey = apiConfigObject.value(apiDefs::key::vpnKey).toString(); - auto qr = qrCodeUtils::generateQrCode(vpnKey.toUtf8()); - m_qrCodes << qrCodeUtils::svgToBase64(QString::fromStdString(toSvgString(qr, 1))); + m_qrCodes = qrCodeUtils::generateQrCodeImageSeries(vpnKey.toUtf8()); emit vpnKeyExportReady(); } @@ -214,6 +213,7 @@ bool ApiConfigsController::updateServiceFromGateway(const int serverIndex, const newApiConfig.insert(configKey::userCountryCode, apiConfig.value(configKey::userCountryCode)); newApiConfig.insert(configKey::serviceType, apiConfig.value(configKey::serviceType)); newApiConfig.insert(configKey::serviceProtocol, apiConfig.value(configKey::serviceProtocol)); + newApiConfig.insert(apiDefs::key::vpnKey, apiConfig.value(apiDefs::key::vpnKey)); newServerConfig.insert(configKey::apiConfig, newApiConfig); newServerConfig.insert(configKey::authData, authData); diff --git a/client/ui/qml/Components/ShareConnectionDrawer.qml b/client/ui/qml/Components/ShareConnectionDrawer.qml index a7910ebc..dd59180b 100644 --- a/client/ui/qml/Components/ShareConnectionDrawer.qml +++ b/client/ui/qml/Components/ShareConnectionDrawer.qml @@ -24,7 +24,7 @@ DrawerType2 { property string configContentHeaderText property string shareButtonText: qsTr("Share") property string copyButtonText: qsTr("Copy") - property bool showSettingsButtonVisible: true + property bool isSelfHostedConfig: true property string configExtension: ".vpn" property string configCaption: qsTr("Save AmneziaVPN config") @@ -153,7 +153,7 @@ DrawerType2 { Layout.leftMargin: 16 Layout.rightMargin: 16 - visible: root.showSettingsButtonVisible + visible: root.isSelfHostedConfig defaultColor: AmneziaStyle.color.transparent hoveredColor: AmneziaStyle.color.translucentWhite @@ -285,6 +285,8 @@ DrawerType2 { delegate: ColumnLayout { width: listView.width + property bool isQrCodeVisible: root.isSelfHostedConfig ? ExportController.qrCodesCount > 0 : ApiConfigsController.qrCodesCount > 0 + Rectangle { id: qrCodeContainer @@ -294,7 +296,7 @@ DrawerType2 { Layout.leftMargin: 16 Layout.rightMargin: 16 - visible: ExportController.qrCodesCount > 0 + visible: isQrCodeVisible color: "white" @@ -302,7 +304,8 @@ DrawerType2 { anchors.fill: parent smooth: false - source: ExportController.qrCodesCount ? ExportController.qrCodes[0] : "" + source: root.isSelfHostedConfig ? (isQrCodeVisible ? ExportController.qrCodes[0] : "") : + (isQrCodeVisible ? ApiConfigsController.qrCodes[0] : "") property bool isFocusable: true @@ -333,15 +336,17 @@ DrawerType2 { Timer { property int index: 0 interval: 1000 - running: ExportController.qrCodesCount > 0 + running: isQrCodeVisible repeat: true onTriggered: { - if (ExportController.qrCodesCount > 0) { + if (isQrCodeVisible) { index++ - if (index >= ExportController.qrCodesCount) { + let qrCodesCount = root.isSelfHostedConfig ? ExportController.qrCodesCount : ApiConfigsController.qrCodesCount + if (index >= qrCodesCount) { index = 0 } - parent.source = ExportController.qrCodes[index] + + parent.source = root.isSelfHostedConfig ? ExportController.qrCodes[index] : ApiConfigsController.qrCodes[index] } } } @@ -359,7 +364,7 @@ DrawerType2 { Layout.leftMargin: 16 Layout.rightMargin: 16 - visible: ExportController.qrCodesCount > 0 + visible: isQrCodeVisible horizontalAlignment: Text.AlignHCenter text: qsTr("To read the QR code in the Amnezia app, select \"Add server\" → \"I have data to connect\" → \"QR code, key or settings file\"") diff --git a/client/ui/qml/Pages2/PageSettingsApiServerInfo.qml b/client/ui/qml/Pages2/PageSettingsApiServerInfo.qml index 05012b46..75c1e893 100644 --- a/client/ui/qml/Pages2/PageSettingsApiServerInfo.qml +++ b/client/ui/qml/Pages2/PageSettingsApiServerInfo.qml @@ -163,7 +163,7 @@ PageType { shareConnectionDrawer.headerText = qsTr("Amnezia Premium subscription key") shareConnectionDrawer.openTriggered() - shareConnectionDrawer.showSettingsButtonVisible = false; + shareConnectionDrawer.isSelfHostedConfig = false; shareConnectionDrawer.shareButtonText = qsTr("Save VPN key to file") shareConnectionDrawer.copyButtonText = qsTr("Copy VPN key")