GUI subsystem: -H=windowsgui + AttachConsole, MB_TOPMOST on test window
drover.exe is now a GUI subsystem binary:
- Double-click no longer flashes a console window — a clean
smoke-test message box opens immediately.
- When run from cmd / PowerShell, AttachConsole reattaches stdout
and stderr to the parent terminal so '--version', 'check', etc.
still print as expected.
- MB_TOPMOST flag added to MessageBox so the window can't be
obscured by other windows on launch (this was the actual cause
of "I clicked but nothing happened" reports).
Verified locally: built with GOOS=windows GOARCH=amd64 -H=windowsgui;
running drover-gui.exe --version prints to PowerShell, drover-gui.exe
gui shows the message box on top of the active window.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -92,7 +92,11 @@ jobs:
|
|||||||
SHORT_SHA="${GITHUB_SHA:0:7}"
|
SHORT_SHA="${GITHUB_SHA:0:7}"
|
||||||
BUILD_DATE="$(date -u +%Y-%m-%d)"
|
BUILD_DATE="$(date -u +%Y-%m-%d)"
|
||||||
mkdir -p bin
|
mkdir -p bin
|
||||||
go build -trimpath -ldflags="-s -w \
|
# -H=windowsgui = subsystem WINDOWS, double-click no longer
|
||||||
|
# flashes a console window. main.go calls AttachConsole on
|
||||||
|
# startup so CLI invocations from cmd/PowerShell still print
|
||||||
|
# to the parent terminal.
|
||||||
|
go build -trimpath -ldflags="-s -w -H=windowsgui \
|
||||||
-X main.Version=dev-${SHORT_SHA} \
|
-X main.Version=dev-${SHORT_SHA} \
|
||||||
-X main.Commit=${SHORT_SHA} \
|
-X main.Commit=${SHORT_SHA} \
|
||||||
-X main.BuildDate=${BUILD_DATE}" \
|
-X main.BuildDate=${BUILD_DATE}" \
|
||||||
|
|||||||
@@ -67,7 +67,11 @@ jobs:
|
|||||||
BUILD_DATE="$(date -u +%Y-%m-%d)"
|
BUILD_DATE="$(date -u +%Y-%m-%d)"
|
||||||
SHORT_SHA="${GITHUB_SHA:0:7}"
|
SHORT_SHA="${GITHUB_SHA:0:7}"
|
||||||
mkdir -p dist
|
mkdir -p dist
|
||||||
go build -trimpath -ldflags="-s -w \
|
# -H=windowsgui makes drover.exe a GUI subsystem binary so the
|
||||||
|
# double-click experience doesn't flash a console window. main.go
|
||||||
|
# calls AttachConsole on startup so CLI runs still print to the
|
||||||
|
# parent terminal when launched from cmd/PowerShell.
|
||||||
|
go build -trimpath -ldflags="-s -w -H=windowsgui \
|
||||||
-X main.Version=${{ steps.version.outputs.version }} \
|
-X main.Version=${{ steps.version.outputs.version }} \
|
||||||
-X main.Commit=${SHORT_SHA} \
|
-X main.Commit=${SHORT_SHA} \
|
||||||
-X main.BuildDate=${BUILD_DATE}" \
|
-X main.BuildDate=${BUILD_DATE}" \
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
//go:build !windows
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
func attachToParentConsole() {}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
//go:build windows
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"syscall"
|
||||||
|
|
||||||
|
"golang.org/x/sys/windows"
|
||||||
|
)
|
||||||
|
|
||||||
|
// attachToParentConsole reconnects stdin/stdout/stderr to the console of the
|
||||||
|
// process that launched us, if any. It is a no-op when the binary was started
|
||||||
|
// from Explorer (double-click) — there is no parent console to attach to.
|
||||||
|
//
|
||||||
|
// Why we need this: the binary is built with -H=windowsgui, which means
|
||||||
|
// Windows treats it as a GUI application and does NOT allocate a console
|
||||||
|
// when it starts. That gives a clean double-click experience (no flashing
|
||||||
|
// console window). But it also disconnects fmt.Println output when the
|
||||||
|
// user runs us from cmd.exe / PowerShell. Calling AttachConsole here
|
||||||
|
// re-attaches us to the parent's console so CLI output works as expected.
|
||||||
|
func attachToParentConsole() {
|
||||||
|
const ATTACH_PARENT_PROCESS = ^uint32(0) // (DWORD)-1
|
||||||
|
|
||||||
|
kernel32 := windows.NewLazySystemDLL("kernel32.dll")
|
||||||
|
attachConsole := kernel32.NewProc("AttachConsole")
|
||||||
|
|
||||||
|
r, _, _ := attachConsole.Call(uintptr(ATTACH_PARENT_PROCESS))
|
||||||
|
if r == 0 {
|
||||||
|
// AttachConsole failed — most likely there is no parent console
|
||||||
|
// (we were started from Explorer). That's fine: GUI mode is the
|
||||||
|
// default UX and stdout/stderr just go nowhere.
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Re-bind os.Stdout / os.Stderr to the freshly-attached console.
|
||||||
|
if h, err := syscall.GetStdHandle(syscall.STD_OUTPUT_HANDLE); err == nil && h != 0 {
|
||||||
|
os.Stdout = os.NewFile(uintptr(h), "stdout")
|
||||||
|
}
|
||||||
|
if h, err := syscall.GetStdHandle(syscall.STD_ERROR_HANDLE); err == nil && h != 0 {
|
||||||
|
os.Stderr = os.NewFile(uintptr(h), "stderr")
|
||||||
|
}
|
||||||
|
if h, err := syscall.GetStdHandle(syscall.STD_INPUT_HANDLE); err == nil && h != 0 {
|
||||||
|
os.Stdin = os.NewFile(uintptr(h), "stdin")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -38,8 +38,10 @@ func showTestWindow() {
|
|||||||
bodyW, _ := windows.UTF16PtrFromString(body)
|
bodyW, _ := windows.UTF16PtrFromString(body)
|
||||||
titleW, _ := windows.UTF16PtrFromString(title)
|
titleW, _ := windows.UTF16PtrFromString(title)
|
||||||
|
|
||||||
// MB_OK | MB_ICONINFORMATION | MB_SETFOREGROUND
|
// MB_OK | MB_ICONINFORMATION | MB_SETFOREGROUND | MB_TOPMOST
|
||||||
const flags = 0x00000000 | 0x00000040 | 0x00010000
|
// MB_TOPMOST is essential — without it the message box can pop up
|
||||||
|
// behind other windows and the user thinks nothing happened.
|
||||||
|
const flags = 0x00000000 | 0x00000040 | 0x00010000 | 0x00040000
|
||||||
|
|
||||||
messageBox.Call(
|
messageBox.Call(
|
||||||
0,
|
0,
|
||||||
|
|||||||
@@ -22,6 +22,12 @@ var (
|
|||||||
var configPath string
|
var configPath string
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
// On Windows the binary is linked with -H=windowsgui so a double-click
|
||||||
|
// doesn't flash a console window. When the user runs us from cmd or
|
||||||
|
// PowerShell we still want stdout/stderr to land in their terminal —
|
||||||
|
// AttachConsole(ATTACH_PARENT_PROCESS) wires that up. No-op elsewhere.
|
||||||
|
attachToParentConsole()
|
||||||
|
|
||||||
// Inject our build version so the updater package can stamp it on the
|
// Inject our build version so the updater package can stamp it on the
|
||||||
// User-Agent header it sends to git.okcu.io.
|
// User-Agent header it sends to git.okcu.io.
|
||||||
updater.SetVersion(Version)
|
updater.SetVersion(Version)
|
||||||
|
|||||||
Reference in New Issue
Block a user