From e9061a221c64cdd72c0ff0af2da118ba6fbca9a7 Mon Sep 17 00:00:00 2001 From: luxick Date: Mon, 3 Aug 2026 19:29:27 +0200 Subject: [PATCH] Hide console on windows The companion does no longer show a terminal window pop up --- cmd/companion/commands.go | 4 +++- cmd/companion/commands_other.go | 8 ++++++++ cmd/companion/commands_windows.go | 18 ++++++++++++++++++ cmd/companion/main.go | 2 +- 4 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 cmd/companion/commands_other.go create mode 100644 cmd/companion/commands_windows.go diff --git a/cmd/companion/commands.go b/cmd/companion/commands.go index 6d2c647..07ff844 100644 --- a/cmd/companion/commands.go +++ b/cmd/companion/commands.go @@ -57,7 +57,9 @@ func runOpenCommand(template, path string) error { if !sawPath { tokens = append(tokens, path) } - return exec.Command(tokens[0], tokens[1:]...).Start() + cmd := exec.Command(tokens[0], tokens[1:]...) + hideConsole(cmd) + return cmd.Start() } // tokenizeCommand splits a command-line string into argv tokens, honouring diff --git a/cmd/companion/commands_other.go b/cmd/companion/commands_other.go new file mode 100644 index 0000000..dac4ee2 --- /dev/null +++ b/cmd/companion/commands_other.go @@ -0,0 +1,8 @@ +//go:build !windows + +package main + +import "os/exec" + +// Allows running commands without showing a terminal window on startup when not running on windows +func hideConsole(*exec.Cmd) {} diff --git a/cmd/companion/commands_windows.go b/cmd/companion/commands_windows.go new file mode 100644 index 0000000..0946071 --- /dev/null +++ b/cmd/companion/commands_windows.go @@ -0,0 +1,18 @@ +package main + +import ( + "os/exec" + "syscall" +) + +// This is the windows CREATE_NO_WINDOW syscall. +// We have no golang.org/x/sys dependency, so this will suffice +const createNoWindow = 0x08000000 + +// Allows running commands without showing a terminal window on startup on windows +func hideConsole(cmd *exec.Cmd) { + cmd.SysProcAttr = &syscall.SysProcAttr{ + HideWindow: true, + CreationFlags: createNoWindow, + } +} diff --git a/cmd/companion/main.go b/cmd/companion/main.go index 761a755..de81939 100644 --- a/cmd/companion/main.go +++ b/cmd/companion/main.go @@ -6,7 +6,7 @@ import ( "path/filepath" ) -const version = "1" +const version = "2" func main() { flag.Parse()