platform: Fixes and improvements

This commit is contained in:
世界
2023-04-05 04:38:56 +08:00
parent 28aa4c4d1f
commit 8b64446274
16 changed files with 33 additions and 31 deletions

View File

@@ -1,5 +1,3 @@
//go:build darwin
package libbox
const (

View File

@@ -1,5 +1,3 @@
//go:build darwin
package libbox
import (
@@ -46,6 +44,7 @@ func clientConnect(sharedDirectory string) (net.Conn, error) {
}
func (c *CommandClient) Connect() error {
common.Close(c.conn)
conn, err := clientConnect(c.sharedDirectory)
if err != nil {
return err

View File

@@ -1,5 +1,3 @@
//go:build darwin
package libbox
import (

View File

@@ -1,5 +1,3 @@
//go:build darwin
package libbox
import (

View File

@@ -1,5 +1,3 @@
//go:build darwin
package libbox
import (

View File

@@ -1,5 +1,3 @@
//go:build darwin
package libbox
import (
@@ -10,6 +8,7 @@ import (
"sync"
"github.com/sagernet/sing-box/log"
"github.com/sagernet/sing/common"
E "github.com/sagernet/sing/common/exceptions"
"github.com/sagernet/sing/common/observable"
"github.com/sagernet/sing/common/x/list"
@@ -57,7 +56,10 @@ func (s *CommandServer) Start() error {
}
func (s *CommandServer) Close() error {
return s.listener.Close()
return common.Close(
s.listener,
s.observer,
)
}
func (s *CommandServer) loopConnection(listener net.Listener) {

View File

@@ -1,5 +1,3 @@
//go:build darwin
package libbox
import (

View File

@@ -1,5 +1,3 @@
//go:build darwin
package libbox
import (

View File

@@ -1,9 +1,9 @@
//go:build linux || darwin
package libbox
import (
"bytes"
"context"
"encoding/json"
"github.com/sagernet/sing-box"
"github.com/sagernet/sing-box/option"
@@ -35,3 +35,19 @@ func CheckConfig(configContent string) error {
}
return err
}
func FormatConfig(configContent string) (string, error) {
options, err := parseConfig(configContent)
if err != nil {
return "", err
}
var buffer bytes.Buffer
json.NewEncoder(&buffer)
encoder := json.NewEncoder(&buffer)
encoder.SetIndent("", " ")
err = encoder.Encode(options)
if err != nil {
return "", err
}
return buffer.String(), nil
}

View File

@@ -1,5 +1,3 @@
//go:build linux || darwin
package libbox
import "github.com/sagernet/sing/common"

View File

@@ -1,5 +1,3 @@
//go:build linux || darwin
package libbox
import "github.com/sagernet/sing-box/option"

View File

@@ -1,5 +1,3 @@
//go:build linux || darwin
package libbox
import (

View File

@@ -1,5 +1,3 @@
//go:build linux || darwin
package libbox
import (

View File

@@ -1,5 +1,3 @@
//go:build linux || darwin
package libbox
import (

View File

@@ -1,5 +1,3 @@
//go:build linux || darwin
package libbox
import (