From e7fa160c9c51f829d93e837d44e4b1ab7d8217b7 Mon Sep 17 00:00:00 2001 From: Nethius Date: Tue, 7 Jan 2025 06:38:32 +0300 Subject: [PATCH] feature: added ad label on page home (#1316) * feature: added ad label on page home --- client/images/controls/external-link.svg | 5 ++ client/resources.qrc | 2 + client/settings.cpp | 10 +++ client/settings.h | 3 + client/ui/controllers/settingsController.cpp | 13 +++- client/ui/controllers/settingsController.h | 7 ++ client/ui/qml/Components/AdLabel.qml | 72 +++++++++++++++++++ client/ui/qml/Modules/Style/AmneziaStyle.qml | 1 + client/ui/qml/Pages2/PageHome.qml | 16 ++++- .../Pages2/PageSetupWizardConfigSource.qml | 26 +++++++ 10 files changed, 151 insertions(+), 4 deletions(-) create mode 100644 client/images/controls/external-link.svg create mode 100644 client/ui/qml/Components/AdLabel.qml diff --git a/client/images/controls/external-link.svg b/client/images/controls/external-link.svg new file mode 100644 index 000000000..6a51c9025 --- /dev/null +++ b/client/images/controls/external-link.svg @@ -0,0 +1,5 @@ + + + + + diff --git a/client/resources.qrc b/client/resources.qrc index 38f0e79ab..ff03a6e7d 100644 --- a/client/resources.qrc +++ b/client/resources.qrc @@ -21,6 +21,7 @@ images/controls/edit-3.svg images/controls/eye-off.svg images/controls/eye.svg + images/controls/external-link.svg images/controls/file-check-2.svg images/controls/file-cog-2.svg images/controls/folder-open.svg @@ -116,6 +117,7 @@ server_scripts/xray/run_container.sh server_scripts/xray/start.sh server_scripts/xray/template.json + ui/qml/Components/AdLabel.qml ui/qml/Components/ConnectButton.qml ui/qml/Components/ConnectionTypeSelectionDrawer.qml ui/qml/Components/HomeContainersListView.qml diff --git a/client/settings.cpp b/client/settings.cpp index 7a572a136..94b11d00e 100644 --- a/client/settings.cpp +++ b/client/settings.cpp @@ -538,3 +538,13 @@ void Settings::toggleDevGatewayEnv(bool enabled) { m_isDevGatewayEnv = enabled; } + +bool Settings::isHomeAdLabelVisible() +{ + return value("Conf/homeAdLabelVisible", true).toBool(); +} + +void Settings::disableHomeAdLabel() +{ + setValue("Conf/homeAdLabelVisible", false); +} diff --git a/client/settings.h b/client/settings.h index f41f4d29a..b383d3da7 100644 --- a/client/settings.h +++ b/client/settings.h @@ -222,6 +222,9 @@ class Settings : public QObject bool isDevGatewayEnv(); void toggleDevGatewayEnv(bool enabled); + bool isHomeAdLabelVisible(); + void disableHomeAdLabel(); + signals: void saveLogsChanged(bool enabled); void screenshotsEnabledChanged(bool enabled); diff --git a/client/ui/controllers/settingsController.cpp b/client/ui/controllers/settingsController.cpp index 6d777bd82..f4e3d83df 100644 --- a/client/ui/controllers/settingsController.cpp +++ b/client/ui/controllers/settingsController.cpp @@ -320,4 +320,15 @@ bool SettingsController::isOnTv() #else return false; #endif -} \ No newline at end of file +} + +bool SettingsController::isHomeAdLabelVisible() +{ + return m_settings->isHomeAdLabelVisible(); +} + +void SettingsController::disableHomeAdLabel() +{ + m_settings->disableHomeAdLabel(); + emit isHomeAdLabelVisibleChanged(false); +} diff --git a/client/ui/controllers/settingsController.h b/client/ui/controllers/settingsController.h index efc18a7d0..7781f6c74 100644 --- a/client/ui/controllers/settingsController.h +++ b/client/ui/controllers/settingsController.h @@ -29,6 +29,8 @@ class SettingsController : public QObject Q_PROPERTY(QString gatewayEndpoint READ getGatewayEndpoint WRITE setGatewayEndpoint NOTIFY gatewayEndpointChanged) Q_PROPERTY(bool isDevGatewayEnv READ isDevGatewayEnv WRITE toggleDevGatewayEnv NOTIFY devGatewayEnvChanged) + Q_PROPERTY(bool isHomeAdLabelVisible READ isHomeAdLabelVisible NOTIFY isHomeAdLabelVisibleChanged) + public slots: void toggleAmneziaDns(bool enable); bool isAmneziaDnsEnabled(); @@ -89,6 +91,9 @@ public slots: bool isOnTv(); + bool isHomeAdLabelVisible(); + void disableHomeAdLabel(); + signals: void primaryDnsChanged(); void secondaryDnsChanged(); @@ -112,6 +117,8 @@ public slots: void gatewayEndpointChanged(const QString &endpoint); void devGatewayEnvChanged(bool enabled); + void isHomeAdLabelVisibleChanged(bool visible); + private: QSharedPointer m_serversModel; QSharedPointer m_containersModel; diff --git a/client/ui/qml/Components/AdLabel.qml b/client/ui/qml/Components/AdLabel.qml new file mode 100644 index 000000000..4133a01cd --- /dev/null +++ b/client/ui/qml/Components/AdLabel.qml @@ -0,0 +1,72 @@ +import QtQuick +import QtQuick.Controls +import QtQuick.Layouts +import QtQuick.Shapes +import Qt5Compat.GraphicalEffects + +import Style 1.0 + +import "../Config" +import "../Controls2" +import "../Controls2/TextTypes" + +Rectangle { + id: root + + property real contentHeight: ad.implicitHeight + ad.anchors.topMargin + ad.anchors.bottomMargin + + border.width: 1 + border.color: AmneziaStyle.color.goldenApricot + color: AmneziaStyle.color.transparent + radius: 13 + + visible: GC.isDesktop() && ServersModel.isDefaultServerFromApi + && ServersModel.isDefaultServerDefaultContainerHasSplitTunneling && SettingsController.isHomeAdLabelVisible + + MouseArea { + anchors.fill: parent + cursorShape: Qt.PointingHandCursor + + onClicked: function() { + Qt.openUrlExternally(LanguageModel.getCurrentSiteUrl() + "/premium") + } + } + + RowLayout { + id: ad + anchors.fill: parent + anchors.margins: 16 + + Image { + source: "qrc:/images/controls/amnezia.svg" + sourceSize: Qt.size(36, 36) + + layer { + effect: ColorOverlay { + color: AmneziaStyle.color.paleGray + } + } + } + + CaptionTextType { + Layout.fillWidth: true + Layout.rightMargin: 10 + Layout.leftMargin: 10 + + text: qsTr("Amnezia Premium - for access to any website") + color: AmneziaStyle.color.pearlGray + + lineHeight: 18 + font.pixelSize: 15 + } + + ImageButtonType { + image: "qrc:/images/controls/close.svg" + imageColor: AmneziaStyle.color.paleGray + + onClicked: function() { + SettingsController.disableHomeAdLabel() + } + } + } +} diff --git a/client/ui/qml/Modules/Style/AmneziaStyle.qml b/client/ui/qml/Modules/Style/AmneziaStyle.qml index 1abfbe3ae..f54fefcee 100644 --- a/client/ui/qml/Modules/Style/AmneziaStyle.qml +++ b/client/ui/qml/Modules/Style/AmneziaStyle.qml @@ -26,5 +26,6 @@ QtObject { readonly property color softGoldenApricot: Qt.rgba(251/255, 178/255, 106/255, 0.3) readonly property color mistyGray: Qt.rgba(215/255, 216/255, 219/255, 0.8) readonly property color cloudyGray: Qt.rgba(215/255, 216/255, 219/255, 0.65) + readonly property color pearlGray: '#EAEAEC' } } diff --git a/client/ui/qml/Pages2/PageHome.qml b/client/ui/qml/Pages2/PageHome.qml index 74db8a137..d5cf8b6e5 100644 --- a/client/ui/qml/Pages2/PageHome.qml +++ b/client/ui/qml/Pages2/PageHome.qml @@ -1,6 +1,7 @@ import QtQuick import QtQuick.Controls import QtQuick.Layouts +import Qt5Compat.GraphicalEffects import SortFilterProxyModel 0.2 @@ -42,8 +43,18 @@ PageType { objectName: "homeColumnLayout" anchors.fill: parent - anchors.topMargin: 34 - anchors.bottomMargin: 34 + anchors.topMargin: 12 + anchors.bottomMargin: 16 + + AdLabel { + id: adLabel + + Layout.fillWidth: true + Layout.preferredHeight: adLabel.contentHeight + Layout.leftMargin: 16 + Layout.rightMargin: 16 + Layout.bottomMargin: 22 + } BasicButtonType { id: loggingButton @@ -86,7 +97,6 @@ PageType { objectName: "splitTunnelingButton" Layout.alignment: Qt.AlignHCenter | Qt.AlignBottom - Layout.bottomMargin: 34 leftPadding: 16 rightPadding: 16 diff --git a/client/ui/qml/Pages2/PageSetupWizardConfigSource.qml b/client/ui/qml/Pages2/PageSetupWizardConfigSource.qml index f5ac64b15..17d733d86 100644 --- a/client/ui/qml/Pages2/PageSetupWizardConfigSource.qml +++ b/client/ui/qml/Pages2/PageSetupWizardConfigSource.qml @@ -206,6 +206,32 @@ PageType { onClicked: { handler() } } } + + footer: ColumnLayout { + width: listView.width + + BasicButtonType { + id: siteLink2 + Layout.topMargin: 24 + Layout.bottomMargin: 16 + Layout.alignment: Qt.AlignHCenter + implicitHeight: 32 + + defaultColor: AmneziaStyle.color.transparent + hoveredColor: AmneziaStyle.color.translucentWhite + pressedColor: AmneziaStyle.color.sheerWhite + disabledColor: AmneziaStyle.color.mutedGray + textColor: AmneziaStyle.color.goldenApricot + + text: qsTr("Site Amnezia") + + rightImageSource: "qrc:/images/controls/external-link.svg" + + clickedFunc: function() { + Qt.openUrlExternally(LanguageModel.getCurrentSiteUrl()) + } + } + } } property list variants: [