From c67cba6625880a2c6d0344c7b70c8736a042600d Mon Sep 17 00:00:00 2001 From: Gouryella Date: Fri, 5 Dec 2025 23:43:15 +0800 Subject: [PATCH] feat (client): Added system dependencies and optimized Windows process check logic - Explicitly included golang.org/x/sys v0.38.0 in go.mod and removed indirect references - Optimized process liveness detection logic on Windows platforms using the golang.org/x/sys/windows package - Used OpenProcess and GetExitCodeProcess instead of Signal detection methods to improve accuracy - Updated command-line output and added an ASCII banner to improve user experience - Added blank lines to the github.com/spf13/cobra package to standardize import format --- go.mod | 2 +- internal/client/cli/daemon_windows.go | 13 +++++++++++-- internal/client/cli/root.go | 12 +++++++++++- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index 57dc939..293b116 100644 --- a/go.mod +++ b/go.mod @@ -10,6 +10,7 @@ require ( github.com/vmihailenco/msgpack/v5 v5.4.1 go.uber.org/zap v1.27.1 golang.org/x/crypto v0.45.0 + golang.org/x/sys v0.38.0 gopkg.in/yaml.v3 v3.0.1 ) @@ -31,6 +32,5 @@ require ( github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect go.uber.org/multierr v1.11.0 // indirect golang.org/x/net v0.47.0 // indirect - golang.org/x/sys v0.38.0 // indirect golang.org/x/text v0.31.0 // indirect ) diff --git a/internal/client/cli/daemon_windows.go b/internal/client/cli/daemon_windows.go index 2e7bd9c..fe34b3b 100644 --- a/internal/client/cli/daemon_windows.go +++ b/internal/client/cli/daemon_windows.go @@ -6,6 +6,8 @@ import ( "os" "os/exec" "syscall" + + "golang.org/x/sys/windows" ) // getSysProcAttr returns platform-specific process attributes for daemonization @@ -17,11 +19,18 @@ func getSysProcAttr() *syscall.SysProcAttr { // isProcessRunningOS checks if a process is running using OS-specific method func isProcessRunningOS(process *os.Process) bool { - err := process.Signal(os.Signal(syscall.Signal(0))) + handle, err := windows.OpenProcess(windows.PROCESS_QUERY_LIMITED_INFORMATION, false, uint32(process.Pid)) if err != nil { return false } - return true + defer windows.CloseHandle(handle) + + var exitCode uint32 + if err := windows.GetExitCodeProcess(handle, &exitCode); err != nil { + return false + } + + return exitCode == 259 } // killProcessOS kills a process using OS-specific method diff --git a/internal/client/cli/root.go b/internal/client/cli/root.go index e96685f..fbee6f8 100644 --- a/internal/client/cli/root.go +++ b/internal/client/cli/root.go @@ -4,6 +4,7 @@ import ( "fmt" "drip/internal/client/cli/ui" + "github.com/spf13/cobra" ) @@ -68,8 +69,17 @@ var versionCmd = &cobra.Command{ return } + banner := ` + ____ _ + | _ \ _ __(_)_ __ + | | | | '__| | '_ \ + | |_| | | | | |_) | + |____/|_| |_| .__/ + |_| + D R I P + ` fmt.Println(ui.Info( - "Drip Client", + banner, "", ui.KeyValue("Version", Version), ui.KeyValue("Git Commit", GitCommit),