From a0fd057bfda06de2159bf173035a88ca3d1dbadd Mon Sep 17 00:00:00 2001
From: "kali kaneko (leap communications)" <kali@leap.se>
Date: Tue, 1 Jun 2021 12:28:47 +0200
Subject: [PATCH] [feat] hide window by default, raise for picking location

---
 gui/qml/MainBar.qml  |  1 -
 gui/qml/VpnState.qml | 12 ++++++------
 gui/qml/main.qml     | 36 +++++++++++++++++++++---------------
 3 files changed, 27 insertions(+), 22 deletions(-)

diff --git a/gui/qml/MainBar.qml b/gui/qml/MainBar.qml
index 1f28bace..a05c1a1a 100644
--- a/gui/qml/MainBar.qml
+++ b/gui/qml/MainBar.qml
@@ -2,7 +2,6 @@ import QtQuick 2.9
 import QtQuick.Controls 2.4
 
 TabBar {
-    //id: bar
     width: parent.width
     TabButton {
         text: qsTr("Status")
diff --git a/gui/qml/VpnState.qml b/gui/qml/VpnState.qml
index 332dcaaf..481d68eb 100644
--- a/gui/qml/VpnState.qml
+++ b/gui/qml/VpnState.qml
@@ -69,9 +69,9 @@ StateGroup {
                 text: {
                     if (autoSelectionButton.checked) {
                         //: %1 -> location to which the client is connected to
-                        qsTr("Best (%1)").arg(locationStr())
+                        qsTr("Recommended (%1)").arg(locationStr())
                     } else {
-                        qsTr("Best")
+                        qsTr("Recommended")
                     }
                 }
             }
@@ -101,9 +101,9 @@ StateGroup {
                 text: {
                     if (autoSelectionButton.checked) {
                         //: %1 -> location to which the client is connected to
-                        qsTr("Best (%1)").arg(locationStr())
+                        qsTr("Recommended (%1)").arg(locationStr())
                     } else {
-                        qsTr("Best")
+                        qsTr("Recommended")
                     }
                 }
             }
@@ -129,7 +129,7 @@ StateGroup {
             }
             PropertyChanges {
                 target: autoSelectionItem
-                text: qsTr("Best")
+                text: qsTr("Recommended")
             }
             PropertyChanges {
                 target: mainStatus
@@ -153,7 +153,7 @@ StateGroup {
             }
             PropertyChanges {
                 target: autoSelectionItem
-                text: qsTr("Best")
+                text: qsTr("Recommended")
             }
             PropertyChanges {
                 target: mainStatus
diff --git a/gui/qml/main.qml b/gui/qml/main.qml
index 3d83b317..cba12a11 100644
--- a/gui/qml/main.qml
+++ b/gui/qml/main.qml
@@ -9,7 +9,7 @@ import "logic.js" as Logic
 
 ApplicationWindow {
     id: app
-    visible: true
+    visible: false
     width: 300
     height: 600
     maximumWidth: 300
@@ -118,7 +118,10 @@ ApplicationWindow {
                     id: autoSelectionButton
                     checked: !isManualLocation()
                     text: qsTr("Recommended")
-                    onClicked: backend.useAutomaticGateway()
+                    onClicked: {
+                        backend.useAutomaticGateway()
+                        manualSelectionItem.checked = false
+                    }
                 }
                 RadioButton {
                     id: manualSelectionButton
@@ -136,6 +139,7 @@ ApplicationWindow {
                     onActivated: {
                         console.debug("Selected gateway:", currentText)
                         backend.useLocation(currentText.toString())
+                        manualSelectionItem.checked = true
                     }
 
                     delegate: ItemDelegate {
@@ -253,6 +257,18 @@ ApplicationWindow {
         if (!ctx.currentLocation) {
             return
         }
+        if (!isManualLocation()) {
+            //manualSelectionItem.checked = isManualLocation()
+            manualSelectionItem.checked = false
+            bar.currentIndex = 1
+            app.visible = true
+            app.hide()
+            app.show()
+            app.raise()
+            return
+        }
+
+        // last used manual selection
         const location = ctx.currentLocation.toLowerCase()
         const idx = gwSelector.model.indexOf(location)
         gwSelector.currentIndex = idx
@@ -265,8 +281,8 @@ ApplicationWindow {
         allowEmptyPass = Logic.shouldAllowEmptyPass(providers)
         needsRestart = false;
         /* TODO get appVisible flag from backend */
-        app.visible = true
-        app.raise()
+        //app.visible = true
+        //app.raise()
     }
 
 
@@ -286,17 +302,6 @@ ApplicationWindow {
         id: systray
         visible: systrayVisible
 
-        onActivated: {
-            if (reason != SystemTrayIcon.Context) {
-                if (app.visible) {
-                    app.hide()
-                } else {
-                    app.show()
-                }
-            }
-        }
-
-
         /* the systray menu cannot be buried in a child qml file because
          * otherwise the ids are not available
          * from other components
@@ -320,6 +325,7 @@ ApplicationWindow {
                 checked: !isManualLocation()
                 onTriggered: {
                     backend.useAutomaticGateway()
+                    manualSelectionItem.checked = false
                 }
             }
 
-- 
GitLab