summaryrefslogtreecommitdiff
path: root/gui/components/Splash.qml
diff options
context:
space:
mode:
authorkali kaneko (leap communications) <kali@leap.se>2021-11-29 01:45:42 +0100
committerkali kaneko (leap communications) <kali@leap.se>2021-11-29 18:14:15 +0100
commitebcef0d57b6ecb5a40c6579f6be07182dd3033ba (patch)
treec46992ece256c11912c50d3e74f1d8d4085b3c46 /gui/components/Splash.qml
parentb7b19b7195366dbacc4078b5b7a3fc6a3ad7889b (diff)
[gui] motd/upgrade style
Diffstat (limited to 'gui/components/Splash.qml')
-rw-r--r--gui/components/Splash.qml152
1 files changed, 147 insertions, 5 deletions
diff --git a/gui/components/Splash.qml b/gui/components/Splash.qml
index cf75108..0d49474 100644
--- a/gui/components/Splash.qml
+++ b/gui/components/Splash.qml
@@ -1,18 +1,52 @@
-import QtQuick 2.9
+import QtQuick 2.15
import QtQuick.Controls 2.2
import QtGraphicalEffects 1.0
+import "../themes/themes.js" as Theme
Page {
id: splash
property int timeoutInterval: qmlDebug ? 200 : 1600
property alias errors: splashErrorBox
+ ToolButton {
+ id: closeButton
+ visible: false
+ anchors {
+ right: parent.right
+ //rightMargin: -10
+ }
+ icon.source: "../resources/close.svg"
+ HoverHandler {
+ cursorShape: Qt.PointingHandCursor
+ }
+ onClicked: {
+ loader.source = "MainView.qml"
+ }
+ }
+
Column {
width: parent.width * 0.8
anchors.horizontalCenter: parent.horizontalCenter
anchors.topMargin: 24
+ MotdBox {
+ id: motd
+ visible: false
+ anchors {
+ top: parent.top
+ topMargin: 100
+ bottomMargin: 30
+ }
+ }
+
VerticalSpacer {
+ id: motdSpacer
+ visible: false
+ height: 100
+ }
+
+ VerticalSpacer {
+ id: upperSpacer
visible: true
height: root.height * 0.25
}
@@ -26,6 +60,7 @@ Page {
}
VerticalSpacer {
+ id: middleSpacer
visible: true
height: root.height * 0.05
}
@@ -40,12 +75,103 @@ Page {
InitErrors {
id: splashErrorBox
}
+ } // end Column
+
+ Image {
+ id: motdImage
+ visible: false
+ height: 100
+ anchors.horizontalCenter: parent.horizontalCenter
+ anchors.bottom: parent.bottom
+ anchors.bottomMargin: 50
+ source: "../resources/icon-noshield.svg"
+ fillMode: Image.PreserveAspectFit
}
Timer {
id: splashTimer
}
+ function hasMotd() {
+ if (ctx) {
+ if (isTrue(ctx.canUpgrade)) {
+ return true
+ }
+ return !isEmpty(ctx.motd)
+ }
+ return false
+ }
+
+ function getUpgradeText() {
+ let t = ""
+ let platform = Qt.platform.os
+ if (platform == "windows" || platform == "osx" || platform == "linux") {
+ t = qsTr("There is a newer version available.")
+ }
+ return t
+ }
+
+ function getUpgradeLink() {
+ return "<a href='" + getLinkURL() + "'>" + qsTr("UPGRADE NOW") + "</a>";
+ }
+
+ function getLinkURL() {
+ return "https://downloads.leap.se/RiseupVPN/" + Qt.platform.os + "/"
+ }
+
+ function showMotd() {
+ // XXX this is not picking locales configured by LANG or LC_ALL
+ let isUpgrade = false
+ let lang = Qt.locale().name.substring(0,2)
+ let messages = JSON.parse(ctx.motd)
+ let platform = Qt.platform.os
+ let textEn = ""
+ let textLocale = ""
+ let link = ""
+
+ if (ctx && isTrue(ctx.canUpgrade)) {
+ isUpgrade = true;
+ textLocale = getUpgradeText();
+ link = getUpgradeLink();
+ } else {
+ // TODO fallback in case upgrade has no text
+ console.debug("configured locale: " + lang)
+ console.debug("platform: " + Qt.platform.os)
+ for (let i=0; i < messages.length; i++) {
+ let m = messages[i]
+ if (m.platform == "all" || m.platform == platform) {
+ for (let k=0; k < m.text.length; k++) {
+ if (m.text[k].lang == lang) {
+ textLocale = m.text[k].str
+ break
+ } else if (m.text[k].lang == "en") {
+ testEn = m.text[k].str
+ }
+ }
+ break
+ }
+ }
+ }
+ if (isUpgrade) {
+ upperSpacer.height = 100
+ } else {
+ // TODO get proportional to textLocale/textEn
+ upperSpacer.height = 50
+ }
+ //connectionImage.height = 100
+ connectionImage.visible = false
+ motdImage.visible = true
+ middleSpacer.visible = false
+ splashProgress.visible = false
+ motd.visible = true
+ motdSpacer.visible = true
+ motd.motdText = textLocale ? textLocale : textEn
+ motd.motdLink = link
+ motd.url = getLinkURL()
+ // FIXME if no text, just skip to main view
+ closeButton.visible = true
+ }
+
function delay(delayTime, cb) {
splashTimer.interval = delayTime
splashTimer.repeat = true
@@ -54,12 +180,16 @@ Page {
}
function loadMainViewWhenReady() {
- if (root.error != "") {
+ if (!isEmpty(root.error)) {
return
}
- if (ctx && ctx.isReady || qmlDebug) {
+ if (ctx && isTrue(ctx.isReady) || qmlDebug) {
splashTimer.stop()
- loader.source = "MainView.qml"
+ if (hasMotd()) {
+ showMotd();
+ } else {
+ loader.source = "MainView.qml"
+ }
} else {
if (!splashTimer.running) {
console.debug('delay...')
@@ -77,5 +207,17 @@ Page {
}
}
- Component.onCompleted: {}
+ Component.onCompleted: {
+ }
+
+ function isTrue(val) {
+ return val == "true";
+ }
+
+ function isEmpty(val) {
+ return val == "";
+ }
+
}
+
+