diff --git a/go.mod b/go.mod index 9e6a233..2f4854c 100644 --- a/go.mod +++ b/go.mod @@ -151,7 +151,7 @@ require ( lukechampine.com/blake3 v1.3.0 // indirect ) -replace github.com/sagernet/sing-box => github.com/hiddify/hiddify-sing-box v1.8.9-0.20241224082119-1aa6bc1919b9 +replace github.com/sagernet/sing-box => github.com/hiddify/hiddify-sing-box v1.8.9-0.20241229165737-711ea7a9f7b2 replace github.com/xtls/xray-core => github.com/hiddify/xray-core v0.0.0-20241219203851-cd7ad9af63bd diff --git a/go.sum b/go.sum index 5264014..b17abbe 100644 --- a/go.sum +++ b/go.sum @@ -241,8 +241,8 @@ github.com/hashicorp/yamux v0.1.2 h1:XtB8kyFOyHXYVFnwT5C3+Bdo8gArse7j2AQ0DA0Uey8 github.com/hashicorp/yamux v0.1.2/go.mod h1:C+zze2n6e/7wshOZep2A70/aQU6QBRWJO/G6FT1wIns= github.com/hectane/go-acl v0.0.0-20230122075934-ca0b05cb1adb h1:PGufWXXDq9yaev6xX1YQauaO1MV90e6Mpoq1I7Lz/VM= github.com/hectane/go-acl v0.0.0-20230122075934-ca0b05cb1adb/go.mod h1:QiyDdbZLaJ/mZP4Zwc9g2QsfaEA4o7XvvgZegSci5/E= -github.com/hiddify/hiddify-sing-box v1.8.9-0.20241224082119-1aa6bc1919b9 h1:Nx3nQS/0VeaBD8ZolNnbO91BrYSZ6NQj2H9Ia3YIIS0= -github.com/hiddify/hiddify-sing-box v1.8.9-0.20241224082119-1aa6bc1919b9/go.mod h1:u16dzx+T4FD39c223mKWT0H0mcHhVRpQaBlN34dPXMk= +github.com/hiddify/hiddify-sing-box v1.8.9-0.20241229165737-711ea7a9f7b2 h1:ofbqvCRR39WDY/5Q+Hpr04ZP+YUqAwzchlkkLOs59V8= +github.com/hiddify/hiddify-sing-box v1.8.9-0.20241229165737-711ea7a9f7b2/go.mod h1:u16dzx+T4FD39c223mKWT0H0mcHhVRpQaBlN34dPXMk= github.com/hiddify/ray2sing v0.0.0-20241219213739-113036bccaba h1:q28rvz9DROJ6P07DlLbSx6cxR00lVp2GYuSCn3WDrpU= github.com/hiddify/ray2sing v0.0.0-20241219213739-113036bccaba/go.mod h1:soYE48y/Q2HtgRFpcX6LcekVyigy7IELYw4fmIGwLSA= github.com/hiddify/warp-plus v0.0.0-20240717223357-4f3122e0d11d h1:vRGKh9ou+/vQGfVYa8MczhbIVjHxlP52OWwrDWO77RA= diff --git a/v2/config/config.go b/v2/config/config.go index 0a374b1..7b34549 100644 --- a/v2/config/config.go +++ b/v2/config/config.go @@ -97,7 +97,7 @@ func getHostnameIfNotIP(inp string) (string, error) { func setOutbounds(options *option.Options, input *option.Options, opt *HiddifyOptions) error { var outbounds []option.Outbound var tags []string - OutboundMainProxyTag = OutboundSelectTag + // OutboundMainProxyTag = OutboundSelectTag // inbound==warp over proxies // outbound==proxies over warp if opt.Warp.EnableWarp { @@ -125,7 +125,7 @@ func setOutbounds(options *option.Options, input *option.Options, opt *HiddifyOp out.Tag = "Hiddify Warp ✅" if opt.Warp.Mode == "warp_over_proxy" { out.WireGuardOptions.Detour = OutboundSelectTag - OutboundMainProxyTag = out.Tag + options.Route.Final = out.Tag } else { out.WireGuardOptions.Detour = OutboundDirectTag } diff --git a/v2/hcore/restart.go b/v2/hcore/restart.go index 434beea..6ba4e35 100644 --- a/v2/hcore/restart.go +++ b/v2/hcore/restart.go @@ -18,9 +18,6 @@ func Restart(in *StartRequest) (coreResponse *CoreInfoResponse, err error) { coreResponse, err = errorWrapper(MessageType_UNEXPECTED_ERROR, recovered_err) }) log.Debug("[Service] Restarting") - if in.ConfigContent == "" && in.ConfigPath == "" { - in = previousStartRequest - } if static.CoreState != CoreStates_STARTED { return errorWrapper(MessageType_INSTANCE_NOT_STARTED, fmt.Errorf("instance not started")) } diff --git a/v2/hcore/start.go b/v2/hcore/start.go index 495e151..05c4b4e 100644 --- a/v2/hcore/start.go +++ b/v2/hcore/start.go @@ -7,6 +7,8 @@ import ( "time" "github.com/hiddify/hiddify-core/v2/config" + "github.com/hiddify/hiddify-core/v2/db" + hcommon "github.com/hiddify/hiddify-core/v2/hcommon" service_manager "github.com/hiddify/hiddify-core/v2/service_manager" box "github.com/sagernet/sing-box" "github.com/sagernet/sing-box/experimental/libbox" @@ -24,13 +26,56 @@ func (s *CoreService) StartService(ctx context.Context, in *StartRequest) (*Core return StartService(in) } +func saveLastStartRequest(in *StartRequest) error { + if in.ConfigContent == "" && in.ConfigPath == "" { + return nil + } + settings := db.GetTable[hcommon.AppSettings]() + return settings.UpdateInsert( + &hcommon.AppSettings{ + Id: "lastStartRequestPath", + Value: in.ConfigPath, + }, + &hcommon.AppSettings{ + Id: "lastStartRequestContent", + Value: in.ConfigContent, + }, + ) +} + +func loadLastStartRequestIfNeeded(in *StartRequest) (*StartRequest, error) { + if in.ConfigContent != "" || in.ConfigPath != "" { + return in, nil + } + settings := db.GetTable[hcommon.AppSettings]() + lastPath, err := settings.Get("lastStartRequestPath") + if err != nil { + return nil, err + } + lastContent, err := settings.Get("lastStartRequestContent") + if err != nil { + return nil, err + } + return &StartRequest{ + ConfigPath: lastPath.Value.(string), + ConfigContent: lastContent.Value.(string), + }, nil +} + func StartService(in *StartRequest) (coreResponse *CoreInfoResponse, err error) { defer config.DeferPanicToError("startmobile", func(recovered_err error) { coreResponse, err = errorWrapper(MessageType_UNEXPECTED_ERROR, recovered_err) }) SetCoreStatus(CoreStates_STARTING, MessageType_EMPTY, "") + + in, err = loadLastStartRequestIfNeeded(in) + if err != nil { + return errorWrapper(MessageType_ERROR_BUILDING_CONFIG, err) + } + previousStartRequest = in options, err := BuildConfig(in) + saveLastStartRequest(in) if err != nil { return errorWrapper(MessageType_ERROR_BUILDING_CONFIG, err) }