mirror of
https://github.com/Mahdi-zarei/nekoray.git
synced 2025-12-18 20:50:09 +08:00
improve extra core path and args handling
This commit is contained in:
parent
8b9350bd43
commit
d760e70977
@ -8,6 +8,7 @@ require (
|
||||
github.com/Mahdi-zarei/speedtest-go v1.7.12
|
||||
github.com/dustin/go-humanize v1.0.1
|
||||
github.com/gofrs/uuid/v5 v5.3.2
|
||||
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
|
||||
github.com/oschwald/maxminddb-golang v1.13.1
|
||||
github.com/sagernet/sing v0.6.9
|
||||
github.com/sagernet/sing-box v1.11.10
|
||||
|
||||
@ -48,6 +48,8 @@ github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
||||
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||
github.com/google/pprof v0.0.0-20231101202521-4ca4178f5c7a h1:fEBsGL/sjAuJrgah5XqmmYsTLzJp/TO9Lhy39gkverk=
|
||||
github.com/google/pprof v0.0.0-20231101202521-4ca4178f5c7a/go.mod h1:czg5+yv1E0ZGTi6S6vVK1mke0fV+FaUhNGcd6VRS9Ik=
|
||||
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaUGG7oYTSPP8MxqL4YI3kZKwcP4=
|
||||
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ=
|
||||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/hashicorp/yamux v0.1.2 h1:XtB8kyFOyHXYVFnwT5C3+Bdo8gArse7j2AQ0DA0Uey8=
|
||||
|
||||
@ -4,23 +4,22 @@ import (
|
||||
"fmt"
|
||||
"github.com/sagernet/sing/common/atomic"
|
||||
"os/exec"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type Process struct {
|
||||
path string
|
||||
args string
|
||||
args []string
|
||||
noOut bool
|
||||
cmd *exec.Cmd
|
||||
stopped atomic.Bool
|
||||
}
|
||||
|
||||
func NewProcess(path string, args string, noOut bool) *Process {
|
||||
func NewProcess(path string, args []string, noOut bool) *Process {
|
||||
return &Process{path: path, args: args, noOut: noOut}
|
||||
}
|
||||
|
||||
func (p *Process) Start() error {
|
||||
p.cmd = exec.Command(p.path, strings.Split(p.args, " ")...)
|
||||
p.cmd = exec.Command(p.path, p.args...)
|
||||
|
||||
p.cmd.Stdout = &pipeLogger{prefix: "Extra Core", noOut: p.noOut}
|
||||
p.cmd.Stderr = &pipeLogger{prefix: "Extra Core", noOut: p.noOut}
|
||||
|
||||
@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/google/shlex"
|
||||
"github.com/sagernet/sing-box/adapter"
|
||||
"github.com/sagernet/sing-box/common/settings"
|
||||
"github.com/sagernet/sing-box/experimental/clashapi"
|
||||
@ -75,7 +76,17 @@ func (s *server) Start(ctx context.Context, in *gen.LoadConfigReq) (out *gen.Err
|
||||
return
|
||||
}
|
||||
_ = f.Close()
|
||||
args := fmt.Sprintf(in.ExtraProcessArgs, extraConfPath)
|
||||
args, e := shlex.Split(in.ExtraProcessArgs)
|
||||
if e != nil {
|
||||
err = E.Cause(e, "Failed to parse args")
|
||||
return
|
||||
}
|
||||
for idx, arg := range args {
|
||||
if strings.Contains(arg, "%s") {
|
||||
args[idx] = fmt.Sprintf(arg, extraConfPath)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
extraProcess = process.NewProcess(in.ExtraProcessPath, args, in.ExtraNoOut)
|
||||
err = extraProcess.Start()
|
||||
|
||||
@ -81,6 +81,9 @@
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QComboBox" name="path_combo">
|
||||
<property name="editable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="frame">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
|
||||
@ -17,7 +17,7 @@
|
||||
<item>
|
||||
<widget class="QTabWidget" name="tabWidget">
|
||||
<property name="currentIndex">
|
||||
<number>1</number>
|
||||
<number>0</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="tab">
|
||||
<attribute name="title">
|
||||
|
||||
Loading…
Reference in New Issue
Block a user