Files
umbrix-libcore/v2/old_command_server.go

54 lines
1.4 KiB
Go
Raw Normal View History

package v2
2023-08-28 13:07:21 +03:30
2023-10-27 14:36:00 +03:30
import (
2024-03-03 04:15:19 +01:00
pb "github.com/hiddify/libcore/hiddifyrpc"
2023-10-27 14:36:00 +03:30
"github.com/sagernet/sing-box/experimental/libbox"
"github.com/sagernet/sing-box/log"
)
2023-08-28 13:07:21 +03:30
var commandServer *libbox.CommandServer
2023-10-27 16:39:48 +03:30
type CommandServerHandler struct {
logger log.Logger
}
2023-08-28 13:07:21 +03:30
func (csh *CommandServerHandler) ServiceReload() error {
2023-10-27 16:39:48 +03:30
csh.logger.Trace("Reloading service")
SetCoreStatus(pb.CoreState_STARTING, pb.MessageType_EMPTY, "")
2023-09-10 20:18:33 +03:30
if commandServer != nil {
commandServer.SetService(nil)
commandServer = nil
}
if Box != nil {
Box.Close()
Box = nil
2023-09-10 20:18:33 +03:30
}
_, err := StartService(&pb.StartRequest{
EnableOldCommandServer: true,
DelayStart: true,
})
return err
2023-08-28 13:07:21 +03:30
}
2023-09-05 19:00:24 +03:30
func (csh *CommandServerHandler) GetSystemProxyStatus() *libbox.SystemProxyStatus {
2023-10-27 16:39:48 +03:30
csh.logger.Trace("Getting system proxy status")
2023-09-05 19:00:24 +03:30
return &libbox.SystemProxyStatus{Available: true, Enabled: false}
}
func (csh *CommandServerHandler) SetSystemProxyEnabled(isEnabled bool) error {
2023-10-27 16:39:48 +03:30
csh.logger.Trace("Setting system proxy status, enabled? ", isEnabled)
2023-10-27 14:36:00 +03:30
return csh.ServiceReload()
2023-09-05 19:00:24 +03:30
}
2024-03-17 21:04:10 +01:00
func (csh *CommandServerHandler) PostServiceClose() {
}
2023-10-27 16:39:48 +03:30
func startCommandServer(logFactory log.Factory) error {
logger := logFactory.NewLogger("[Command Server Handler]")
logger.Trace("Starting command server")
commandServer = libbox.NewCommandServer(&CommandServerHandler{logger: logger}, 300)
2023-08-28 13:07:21 +03:30
return commandServer.Start()
}