refactor(core): add headless run and auto-restart
- Run without console by default - Log to file once console hidden - Recover panics in background goroutines - Restart agent after unexpected errors - Use shared instance launch helper
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
//go:build windows
|
||||
|
||||
package instance
|
||||
|
||||
import (
|
||||
"os"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
var (
|
||||
kernel32 = syscall.NewLazyDLL("kernel32.dll")
|
||||
procFreeConsole = kernel32.NewProc("FreeConsole")
|
||||
user32 = syscall.NewLazyDLL("user32.dll")
|
||||
procShowWindow = user32.NewProc("ShowWindow")
|
||||
)
|
||||
|
||||
const swHide = 0
|
||||
|
||||
// HideConsole hides any console window and detaches from it.
|
||||
func HideConsole() {
|
||||
hwnd, _, _ := kernel32.NewProc("GetConsoleWindow").Call()
|
||||
if hwnd != 0 {
|
||||
_, _, _ = procShowWindow.Call(hwnd, swHide)
|
||||
}
|
||||
_, _, _ = procFreeConsole.Call()
|
||||
redirectStdioToNul()
|
||||
}
|
||||
|
||||
func redirectStdioToNul() {
|
||||
nul, err := os.OpenFile("NUL", os.O_RDWR, 0)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
os.Stdin = nul
|
||||
os.Stdout = nul
|
||||
os.Stderr = nul
|
||||
}
|
||||
Reference in New Issue
Block a user