From a69bc48394b66b068ef7929881aa09a8f74e5430 Mon Sep 17 00:00:00 2001 From: chechao Date: Wed, 23 Apr 2025 18:43:24 +0800 Subject: [PATCH] second commit --- service.go | 4 ++++ service_mac.go | 10 ++++++++++ service_win.go | 13 +++++++++++++ 3 files changed, 27 insertions(+) create mode 100644 service_mac.go create mode 100644 service_win.go diff --git a/service.go b/service.go index 784ccd8..3a3b37d 100644 --- a/service.go +++ b/service.go @@ -10,6 +10,7 @@ import ( "os" "os/exec" "regexp" + "runtime" "strconv" "strings" "time" @@ -234,6 +235,9 @@ func newService(cmd *exec.Cmd, urlPrefix string, port int, opts ...ServiceOption cmd.Stderr = s.output cmd.Stdout = s.output cmd.Env = os.Environ() + if runtime.GOOS == "windows" { + setHideWindow(cmd) + } // TODO(minusnine): Pdeathsig is only supported on Linux. Somehow, make sure // process cleanup happens as gracefully as possible. if s.display != "" { diff --git a/service_mac.go b/service_mac.go new file mode 100644 index 0000000..ba14b13 --- /dev/null +++ b/service_mac.go @@ -0,0 +1,10 @@ +//go:build !windows +// +build !windows + +package selenium + +import "os/exec" + +func setHideWindow(cmd *exec.Cmd) { + // 非Windows平台无操作 +} diff --git a/service_win.go b/service_win.go new file mode 100644 index 0000000..0f1a457 --- /dev/null +++ b/service_win.go @@ -0,0 +1,13 @@ +//go:build windows +// +build windows + +package selenium + +import ( + "os/exec" + "syscall" +) + +func setHideWindow(cmd *exec.Cmd) { + cmd.SysProcAttr = &syscall.SysProcAttr{HideWindow: true} +}