Skip to content

Commit 46a2de3

Browse files
Add files via upload
1 parent b6a582e commit 46a2de3

3 files changed

Lines changed: 33 additions & 10 deletions

File tree

core_engine/main.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"net/http"
1111
"os"
1212
"os/exec"
13+
"runtime"
1314
"strings"
1415
"sync"
1516
"time"
@@ -49,19 +50,18 @@ func main() {
4950
var cmd *exec.Cmd
5051
var configFile *os.File
5152

52-
if c.Protocol == "hysteria" || c.Protocol == "hysteria2" || c.Protocol == "hy2" {
53+
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
54+
defer cancel()
5355

56+
if c.Protocol == "hysteria" || c.Protocol == "hysteria2" {
5457
configFile, err = os.CreateTemp("", "hysteria-*.json")
5558
if err != nil { results <- TestResult{Tag: c.Tag, Ping: -1, Status: "tempfile_error"}; return }
5659
defer os.Remove(configFile.Name())
57-
5860
configFile.Write(c.Config)
5961
configFile.Close()
60-
61-
cmd = exec.Command(c.ClientPath, "client", "-c", configFile.Name())
62+
cmd = exec.CommandContext(ctx, c.ClientPath, "client", "-c", configFile.Name())
6263

6364
} else {
64-
6565
configFile, err = os.CreateTemp("", "xray-*.json")
6666
if err != nil { results <- TestResult{Tag: c.Tag, Ping: -1, Status: "tempfile_error"}; return }
6767
defer os.Remove(configFile.Name())
@@ -82,13 +82,13 @@ func main() {
8282
configFile.Write(configBytes)
8383
configFile.Close()
8484

85-
cmd = exec.Command(c.ClientPath, "-c", configFile.Name())
85+
cmd = exec.CommandContext(ctx, c.ClientPath, "-c", configFile.Name())
8686
}
8787

88-
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
89-
defer cancel()
90-
cmd.SysProcAttr = &exec.SysProcAttr{HideWindow: true}
91-
cmd.Cancel = func() error { return cmd.Process.Kill() }
88+
89+
if runtime.GOOS == "windows" {
90+
setHideWindow(cmd)
91+
}
9292

9393
var clientOutput bytes.Buffer
9494
cmd.Stdout = &clientOutput

core_engine/sys_other.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//go:build !windows
2+
3+
package main
4+
5+
import (
6+
"os/exec"
7+
)
8+
9+
func setHideWindow(cmd *exec.Cmd) {
10+
// No-op on Linux and macOS, as there's no console window to hide
11+
}

core_engine/sys_windows.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//go:build windows
2+
3+
package main
4+
5+
import (
6+
"os/exec"
7+
"syscall"
8+
)
9+
10+
func setHideWindow(cmd *exec.Cmd) {
11+
cmd.SysProcAttr = &syscall.SysProcAttr{HideWindow: true}
12+
}

0 commit comments

Comments
 (0)