diff --git a/adapter/network.go b/adapter/network.go index 00ef54b8..3adfaaeb 100644 --- a/adapter/network.go +++ b/adapter/network.go @@ -25,6 +25,7 @@ type NetworkManager interface { PackageManager() tun.PackageManager WIFIState() WIFIState ResetNetwork() + UpdateWIFIState() } type NetworkOptions struct { diff --git a/experimental/libbox/command_power.go b/experimental/libbox/command_power.go index 5ed7b014..00906490 100644 --- a/experimental/libbox/command_power.go +++ b/experimental/libbox/command_power.go @@ -4,7 +4,6 @@ import ( "encoding/binary" "net" - E "github.com/sagernet/sing/common/exceptions" "github.com/sagernet/sing/common/varbin" ) @@ -18,19 +17,7 @@ func (c *CommandClient) ServiceReload() error { if err != nil { return err } - var hasError bool - err = binary.Read(conn, binary.BigEndian, &hasError) - if err != nil { - return err - } - if hasError { - errorMessage, err := varbin.ReadValue[string](conn, binary.BigEndian) - if err != nil { - return err - } - return E.New(errorMessage) - } - return nil + return readError(conn) } func (s *CommandServer) handleServiceReload(conn net.Conn) error { @@ -55,19 +42,7 @@ func (c *CommandClient) ServiceClose() error { if err != nil { return err } - var hasError bool - err = binary.Read(conn, binary.BigEndian, &hasError) - if err != nil { - return nil - } - if hasError { - errorMessage, err := varbin.ReadValue[string](conn, binary.BigEndian) - if err != nil { - return nil - } - return E.New(errorMessage) - } - return nil + return readError(conn) } func (s *CommandServer) handleServiceClose(conn net.Conn) error { diff --git a/experimental/libbox/service_pause.go b/experimental/libbox/service_pause.go index a7599a76..0fa9541f 100644 --- a/experimental/libbox/service_pause.go +++ b/experimental/libbox/service_pause.go @@ -31,3 +31,7 @@ func (s *BoxService) Wake() { func (s *BoxService) ResetNetwork() { s.instance.Router().ResetNetwork() } + +func (s *BoxService) UpdateWIFIState() { + s.instance.Network().UpdateWIFIState() +} diff --git a/route/network.go b/route/network.go index 97d165f1..ab1be76c 100644 --- a/route/network.go +++ b/route/network.go @@ -354,6 +354,18 @@ func (r *NetworkManager) WIFIState() adapter.WIFIState { return r.wifiState } +func (r *NetworkManager) UpdateWIFIState() { + if r.platformInterface != nil { + state := r.platformInterface.ReadWIFIState() + if state != r.wifiState { + r.wifiState = state + if state.SSID != "" { + r.logger.Info("updated WIFI state: SSID=", state.SSID, ", BSSID=", state.BSSID) + } + } + } +} + func (r *NetworkManager) ResetNetwork() { conntrack.Close() @@ -414,15 +426,7 @@ func (r *NetworkManager) notifyInterfaceUpdate(defaultInterface *control.Interfa } } r.logger.Info("updated default interface ", defaultInterface.Name, ", ", strings.Join(options, ", ")) - if r.platformInterface != nil { - state := r.platformInterface.ReadWIFIState() - if state != r.wifiState { - r.wifiState = state - if state.SSID != "" { - r.logger.Info("updated WIFI state: SSID=", state.SSID, ", BSSID=", state.BSSID) - } - } - } + r.UpdateWIFIState() if !r.started { return