Skip to content

Commit f8b7194

Browse files
committed
refactor(windows): use utils/winapi for console hiding
Move ShowWindow / GetConsoleWindow proc declarations into utils/winapi to follow the existing centralization convention (see review feedback). Adds a User32 LazyDLL handle and a typed HideConsoleWindow() wrapper. main_windows.go is now a thin caller that uses the wrapper.
1 parent f67662d commit f8b7194

3 files changed

Lines changed: 24 additions & 14 deletions

File tree

cmd/hack-browser-data/main_windows.go

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,8 @@ package main
55
import (
66
"github.com/inconshreveable/mousetrap"
77
"github.com/spf13/cobra"
8-
"golang.org/x/sys/windows"
9-
)
10-
11-
const swHide = 0
128

13-
var (
14-
kernel32 = windows.NewLazySystemDLL("kernel32.dll")
15-
user32 = windows.NewLazySystemDLL("user32.dll")
16-
procGetConsoleWindow = kernel32.NewProc("GetConsoleWindow")
17-
procShowWindow = user32.NewProc("ShowWindow")
9+
"github.com/moond4rk/hackbrowserdata/utils/winapi"
1810
)
1911

2012
// configureDoubleClickMode hides the console and bypasses cobra's
@@ -25,9 +17,5 @@ func configureDoubleClickMode() {
2517
}
2618

2719
cobra.MousetrapHelpText = ""
28-
29-
hwnd, _, _ := procGetConsoleWindow.Call()
30-
if hwnd != 0 {
31-
_, _, _ = procShowWindow.Call(hwnd, swHide)
32-
}
20+
winapi.HideConsoleWindow()
3321
}

utils/winapi/console_windows.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//go:build windows
2+
3+
package winapi
4+
5+
var (
6+
procGetConsoleWindow = Kernel32.NewProc("GetConsoleWindow")
7+
procShowWindow = User32.NewProc("ShowWindow")
8+
)
9+
10+
const swHide = 0
11+
12+
// HideConsoleWindow hides the console window attached to the current
13+
// process. Used when the binary is launched via Explorer double-click
14+
// so no cmd window appears.
15+
func HideConsoleWindow() {
16+
hwnd, _, _ := procGetConsoleWindow.Call()
17+
if hwnd == 0 {
18+
return
19+
}
20+
_, _, _ = procShowWindow.Call(hwnd, swHide)
21+
}

utils/winapi/winapi_windows.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ var (
2424
Kernel32 = windows.NewLazySystemDLL("kernel32.dll")
2525
Ntdll = windows.NewLazySystemDLL("ntdll.dll")
2626
Crypt32 = windows.NewLazySystemDLL("crypt32.dll")
27+
User32 = windows.NewLazySystemDLL("user32.dll")
2728
)
2829

2930
// CallBoolErr wraps the common "r1 == 0 means failure" Win32 convention.

0 commit comments

Comments
 (0)