From a540f3f4e5524b5daf813b0bb831707f58545d43 Mon Sep 17 00:00:00 2001
From: kali <kali@win>
Date: Thu, 15 Oct 2020 17:27:59 +0200
Subject: [PATCH] [pkg] windows gui & installer fixes

---
 Makefile                                      | 16 ++++++-----
 .../templates/qtinstaller/config/config.xml   |  2 +-
 docs/build.windows.rst                        | 27 ++++++++++++-------
 gui/qml/main.qml                              | 23 +++-------------
 pkg/config/logger.go                          |  2 +-
 5 files changed, 33 insertions(+), 37 deletions(-)

diff --git a/Makefile b/Makefile
index 28b03f7b..9faf55ca 100644
--- a/Makefile
+++ b/Makefile
@@ -73,11 +73,15 @@ EXTRA_FLAGS =
 endif
 
 ifeq ($(PLATFORM), windows)
-EXTRA_GO_LDFLAGS = "-H windowsgui"
+EXTRA_GO_LDFLAGS = "-H=windowsgui"
 endif
 
-
+ifeq ($(PLATFORM), windows)
+PKGFILES = $(wildcard "pkg/*") # syntax err in windows with find 
+else
 PKGFILES = $(shell find pkg -type f -name '*.go')
+endif
+
 lib/%.a: $(PKGFILES)
 	@./gui/build.sh --just-golib
 
@@ -118,9 +122,9 @@ ifeq (${PLATFORM}, darwin)
 	@cp -r "${QTBUILD}/release/${TARGET}.app"/ ${INST_DATA}/
 endif
 ifeq (${PLATFORM}, windows)
-	@VERSION=${VERSION} ${SCRIPTS}/gen-qtinstaller windows ${INSTALLER}
+	@VERSION=${VERSION} VENDOR_PATH=${VENDOR_PATH} ${SCRIPTS}/gen-qtinstaller windows ${INSTALLER}
 	@cp build/bin/${PLATFORM}/bitmask-helper ${INST_DATA}helper.exe
-	@cp branding/assets/${PROVIDER}/icon.ico ${INST_DATA}/icon.ico
+	@cp ${VENDOR_PATH}/${PROVIDER}/assets/icon.ico ${INST_DATA}/icon.ico
 	@cp ${QTBUILD}/release/${TARGET}.exe ${INST_DATA}${TARGET}.exe
 	# FIXME get the signed binaries with curl from openvpn downloads page - see if we have to adapt the openvpn-build to install tap drivers etc from our installer.
 	@cp "/c/Program Files/OpenVPN/bin/openvpn.exe" ${INST_DATA}
@@ -146,13 +150,13 @@ endif
 
 CROSS_WIN_FLAGS = CGO_ENABLED=1 GOARCH=386 GOOS=windows CC="/usr/bin/i686-w64-mingw32-gcc" CGO_LDFLAGS="-lssp" CXX="i686-w64-mingw32-c++"
 PLATFORM_WIN = PLATFORM=windows
-EXTRA_LDFLAGS_WIN = EXTRA_LDFLAGS="-H windowsgui" 
+EXTRA_LDFLAGS_WIN = EXTRA_LDFLAGS="-H=windowsgui" 
 build_cross_win:
 	@echo "[+] Cross-building for windows..."
 	@$(CROSS_WIN_FLAGS) $(PLATFORM_WIN) $(EXTRA_LDFLAGS_WIN) $(MAKE) _buildparts
 	# workaround for helper: we use the go compiler
 	@echo "[+] Compiling helper with the Go compiler to work around missing stdout bug..."
-	cd cmd/bitmask-helper && GOOS=windows GOARCH=386 go build -ldflags "-X main.version=`git describe --tags` -H windowsgui" -o ../../build/bin/windows/bitmask-helper-go
+	cd cmd/bitmask-helper && GOOS=windows GOARCH=386 go build -ldflags "-X main.version=`git describe --tags` -H=windowsgui" -o ../../build/bin/windows/bitmask-helper-go
 
 CROSS_OSX_FLAGS = MACOSX_DEPLOYMENT_TARGET=10.10 CGO_ENABLED=1 GOOS=darwin CC="o64-clang"
 PLATFORM_OSX = PLATFORM=darwin
diff --git a/branding/templates/qtinstaller/config/config.xml b/branding/templates/qtinstaller/config/config.xml
index 70ce9f60..13dba490 100644
--- a/branding/templates/qtinstaller/config/config.xml
+++ b/branding/templates/qtinstaller/config/config.xml
@@ -14,7 +14,7 @@
     </RemoteRepositories>
     -->
 
-    <MaintenanceToolName>Uninstall-$APPNAME</MaintenanceToolName>
+    <MaintenanceToolName>uninstall</MaintenanceToolName>
 
     $PLATFORM_BLOCK
 
diff --git a/docs/build.windows.rst b/docs/build.windows.rst
index 9fa0ff94..1e8364dd 100644
--- a/docs/build.windows.rst
+++ b/docs/build.windows.rst
@@ -1,10 +1,17 @@
-windows build notes (still some manual steps needed, this should be further automated).
-=======================================================================================
-(deprecated)
-
-PROVIDER=DemoLib make helper
-INSTALLER_DATA=branding/qtinstaller/packages/root.win_x86_64/data/
-mkdir -p INSTALLER_DATA
-mv main.exe ${INSTALLER_DATA}/helper.exe
-TARGET=demolib-vpn make build
-TARGET=demolib-vpn make installer_win
+windows build
+=============
+
+The build currently expects MINGW64 environment, on a native windows host.
+A cross-compiling procedure (at least for the application binaries) should be possible in the near future, using mxe.
+
+You should install make, as well as a recent Qt5 version (for instance, with chocolatey: choco install make).
+
+(In order to avoid makefiles, you are welcome to submit a port of the build scripts using powershell or cscript - see the build.wsf script in openvpn-build for inspiration).
+
+For the installer, install QtIFW for windows (tested with version 3.2.2).
+
+Assuming you have the vendor path in place and correctly configured, all you need to do is `make build_installer`::
+
+  export PATH="/c/Qt/Qt5/bin/":"/c/Qt/QtIFW-3.2.2/bin":$PATH
+  VENDOR_PATH=providers/
+  make build_installer
diff --git a/gui/qml/main.qml b/gui/qml/main.qml
index 04592a5a..a3218dec 100644
--- a/gui/qml/main.qml
+++ b/gui/qml/main.qml
@@ -88,28 +88,13 @@ ApplicationWindow {
 
     Component.onCompleted: {
         loginDone = false;
-
+        console.debug("Platform:", Qt.platform.os);
         console.debug("DEBUG: Pre-seeded providers:");
         console.debug(providers.getJson());
+        allowEmptyPass = shouldAllowEmptyPass();
 
-        allowEmptyPass = shouldAllowEmptyPass()
-
-        console.debug("DEBUG platform":, Qt.platform.os)
-
-        if ("osx" == Qt.platform.os || "linux" == Qt.platform.os ) {
-            app.visible = false;
-        }
-
-        if ("windows" == Qt.platform.os) {
-            /* FIXME stupid as it sounds, windows doesn't like to have the systray icon
-             not being attached to an actual application window??
-             We can still use this quirk, and can use the AppWindow with deferred
-             Loaders as a placeholder for all the many dialogs, or to load
-             a nice splash screen etc...  */
-            app.visible = true;
-            app.show();
-            app.hide();
-        }
+	/* TODO get appVisible flag from backend */
+        app.visible = false;
     }
 
     function toHuman(st) {
diff --git a/pkg/config/logger.go b/pkg/config/logger.go
index cc7a4f65..a4a979a2 100644
--- a/pkg/config/logger.go
+++ b/pkg/config/logger.go
@@ -29,7 +29,7 @@ func ConfigureLogger(logPath string) (io.Closer, error) {
 		if os.IsNotExist(err) {
 			err := os.MkdirAll(dir, 0700)
 			if err == nil {
-				log.Println("ERROR: cannot create data dir")
+				log.Println("ERROR: cannot create data dir:", dir)
 			}
 		}
 	}
-- 
GitLab