This is an automated email from the ASF dual-hosted git repository.

hsluoyz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/casbin-gateway.git


The following commit(s) were added to refs/heads/master by this push:
     new 02caaaf  fix(desktop): stop the Windows launcher from opening a 
console window
02caaaf is described below

commit 02caaaf1d823839fa8e6fa83f0377b764220bb93
Author: Yang Luo <[email protected]>
AuthorDate: Thu Sep 3 13:42:37 2026 +0800

    fix(desktop): stop the Windows launcher from opening a console window
---
 .github/workflows/nightly.yml |  3 ++-
 desktop/console_other.go      | 19 ++++++++++++++++++
 desktop/console_windows.go    | 45 +++++++++++++++++++++++++++++++++++++++++++
 desktop/main.go               |  1 +
 scripts/install.ps1           | 10 ++++++++--
 5 files changed, 75 insertions(+), 3 deletions(-)

diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml
index 1f85703..650e41c 100644
--- a/.github/workflows/nightly.yml
+++ b/.github/workflows/nightly.yml
@@ -175,9 +175,10 @@ jobs:
             # macOS comes from the job that ran on a macOS runner.
             desktopBinary="${stage}/casbin-gateway-desktop"
             case "${goos}" in
+              # -H windowsgui: no console window behind the tray icon.
               windows)
                 (cd desktop && GOOS=windows GOARCH="${goarch}" CGO_ENABLED=0 \
-                  go build -trimpath -ldflags "-s -w" -o 
"../${desktopBinary}.exe" .)
+                  go build -trimpath -ldflags "-s -w -H windowsgui" -o 
"../${desktopBinary}.exe" .)
                 ;;
               linux)
                 (cd desktop && CGO_ENABLED=1 
PKG_CONFIG_PATH="${RUNNER_TEMP}/pkgconfig" \
diff --git a/desktop/console_other.go b/desktop/console_other.go
new file mode 100644
index 0000000..35ffba9
--- /dev/null
+++ b/desktop/console_other.go
@@ -0,0 +1,19 @@
+// Copyright 2026 The casbin Authors. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+//go:build !windows
+
+package main
+
+func dropOwnConsole() {}
diff --git a/desktop/console_windows.go b/desktop/console_windows.go
new file mode 100644
index 0000000..7514746
--- /dev/null
+++ b/desktop/console_windows.go
@@ -0,0 +1,45 @@
+// Copyright 2026 The casbin Authors. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package main
+
+import (
+       "syscall"
+       "unsafe"
+)
+
+var (
+       kernel32 = syscall.NewLazyDLL("kernel32.dll")
+
+       procFreeConsole           = kernel32.NewProc("FreeConsole")
+       procGetConsoleWindow      = kernel32.NewProc("GetConsoleWindow")
+       procGetConsoleProcessList = kernel32.NewProc("GetConsoleProcessList")
+)
+
+// dropOwnConsole closes the console Windows hands a plain "go build" started
+// from Explorer. The released builds are linked with -H windowsgui and get
+// none. A console shared with a terminal is left alone.
+func dropOwnConsole() {
+       hwnd, _, _ := procGetConsoleWindow.Call()
+       if hwnd == 0 {
+               return
+       }
+
+       var pids [2]uint32
+       attached, _, _ := 
procGetConsoleProcessList.Call(uintptr(unsafe.Pointer(&pids[0])), 
uintptr(len(pids)))
+       if attached != 1 {
+               return
+       }
+       _, _, _ = procFreeConsole.Call()
+}
diff --git a/desktop/main.go b/desktop/main.go
index 7d5557b..38c02fa 100644
--- a/desktop/main.go
+++ b/desktop/main.go
@@ -68,5 +68,6 @@ func main() {
                return
        }
 
+       dropOwnConsole()
        runTray()
 }
diff --git a/scripts/install.ps1 b/scripts/install.ps1
index 5050112..904558d 100644
--- a/scripts/install.ps1
+++ b/scripts/install.ps1
@@ -108,7 +108,10 @@ if ($UserPath -notlike "*$BinDir*") {
 # ── desktop and Start menu shortcuts 
──────────────────────────────────────────
 # Both point at the desktop launcher, not at the server: it is what shows the
 # window, and it starts the server itself if nothing is serving yet.
-$IconPath = & $DesktopExePath icon
+# The launcher is a GUI binary, whose output PowerShell cannot capture, so the
+# icon path is spelled out rather than read back.
+Start-Process -FilePath $DesktopExePath -ArgumentList 'icon' -WorkingDirectory 
$InstallDir -Wait
+$IconPath = Join-Path $InstallDir 'casbin-gateway.ico'
 $ShortcutName = 'Casbin Gateway.lnk'
 
 function New-GatewayShortcut {
@@ -141,7 +144,10 @@ if (-not $env:NO_SHORTCUT) {
 Remove-Item -Path (Join-Path ([System.Environment]::GetFolderPath('Startup')) 
$ShortcutName) -Force -ErrorAction SilentlyContinue
 if (-not $env:NO_AUTOSTART) {
     try {
-        & $DesktopExePath autostart on
+        $autostart = Start-Process -FilePath $DesktopExePath -ArgumentList 
'autostart', 'on' -WorkingDirectory $InstallDir -Wait -PassThru
+        if ($autostart.ExitCode -ne 0) {
+            throw "the launcher exited with $($autostart.ExitCode)"
+        }
         Write-Info 'Casbin Gateway will start with Windows.'
     }
     catch {


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to