From cab0ccc792240e88a25fc7d955906beeff1e36a8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Blin?=
 <sebastien.blin@savoirfairelinux.com>
Date: Thu, 23 Dec 2021 14:22:08 -0500
Subject: [PATCH] mainapplication: fix --minimized option

remove useless isFullscreen (visibility already stores this and
it's not possible to go from fullscreen to minimized anyway).
Also --minimized was ignored

GitLab: #413
Change-Id: I610f17ce7ae5b2852aae5b40dc504174fa657c2d
---
 src/MainApplicationWindow.qml | 28 ++++++++++++----------------
 src/appsettingsmanager.h      |  1 +
 src/mainapplication.cpp       |  3 +++
 3 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/src/MainApplicationWindow.qml b/src/MainApplicationWindow.qml
index 7707c3989..c554b2c61 100644
--- a/src/MainApplicationWindow.qml
+++ b/src/MainApplicationWindow.qml
@@ -47,10 +47,13 @@ ApplicationWindow {
     }
 
     property ApplicationWindow appWindow : root
-    property bool isFullScreen: false
 
     function toggleFullScreen() {
-        isFullScreen = !isFullScreen
+        if (visibility !== Window.FullScreen) {
+            showFullScreen()
+        } else {
+            showNormal()
+        }
     }
 
     function checkLoadedSource() {
@@ -86,11 +89,6 @@ ApplicationWindow {
             hide()
     }
 
-    visibility: !visible ?
-                   Window.Hidden : (isFullScreen ?
-                                        Window.FullScreen :
-                                        Window.Windowed)
-
     title: JamiStrings.appTitle
 
     width: {
@@ -150,6 +148,9 @@ ApplicationWindow {
         }
 
         onLoaded: {
+            if (UtilsAdapter.getAppValue(Settings.StartMinimized)) {
+                showMinimized()
+            }
             // Quiet check for updates on start if set to.
             if (UtilsAdapter.getAppValue(Settings.AutoUpdate)) {
                 UpdateManager.checkForUpdates(true)
@@ -163,21 +164,16 @@ ApplicationWindow {
 
         function onRestoreAppRequested() {
             requestActivate()
-            if (isFullScreen)
-                showFullScreen()
-            else
+            if (visibility === Window.Hidden || visibility === Window.Minimized) {
                 showNormal()
+            }
         }
 
         function onNotificationClicked() {
             requestActivate()
             raise()
-            if (visibility === Window.Hidden ||
-                    visibility === Window.Minimized) {
-                if (isFullScreen)
-                    showFullScreen()
-                else
-                    showNormal()
+            if (visibility === Window.Hidden || visibility === Window.Minimized) {
+                showNormal()
             }
         }
     }
diff --git a/src/appsettingsmanager.h b/src/appsettingsmanager.h
index 668b1e50d..0e4f315f3 100644
--- a/src/appsettingsmanager.h
+++ b/src/appsettingsmanager.h
@@ -43,6 +43,7 @@ const QString defaultDownloadPath = QStandardPaths::writableLocation(
     X(DisplayHyperlinkPreviews, true) \
     X(EnableDarkTheme, false) \
     X(AutoUpdate, true) \
+    X(StartMinimized, false) \
     X(NeverShowMeAgain, false)
 
 /*
diff --git a/src/mainapplication.cpp b/src/mainapplication.cpp
index 6c9832119..9e623e2b7 100644
--- a/src/mainapplication.cpp
+++ b/src/mainapplication.cpp
@@ -247,6 +247,9 @@ MainApplication::init()
     lrcInstance_->accountModel().autoTransferSizeThreshold = acceptTransferBelow;
 
     initQmlLayer();
+
+    settingsManager_->setValue(Settings::Key::StartMinimized, results[opts::STARTMINIMIZED].toBool());
+
     initSystray();
 
     return true;
-- 
GitLab