mirror of
https://github.com/SagerNet/sing-box.git
synced 2024-11-10 02:53:12 +00:00
44 lines
1,005 B
Go
44 lines
1,005 B
Go
package settings
|
|
|
|
import (
|
|
"os"
|
|
"strings"
|
|
|
|
"github.com/sagernet/sing-box/adapter"
|
|
C "github.com/sagernet/sing-box/constant"
|
|
F "github.com/sagernet/sing/common/format"
|
|
"github.com/sagernet/sing/common/shell"
|
|
)
|
|
|
|
var (
|
|
useRish bool
|
|
rishPath string
|
|
)
|
|
|
|
func init() {
|
|
userId := os.Getuid()
|
|
if userId == 0 || userId == 1000 || userId == 2000 {
|
|
useRish = false
|
|
} else {
|
|
rishPath, useRish = C.FindPath("rish")
|
|
}
|
|
}
|
|
|
|
func runAndroidShell(name string, args ...string) error {
|
|
if !useRish {
|
|
return shell.Exec(name, args...).Attach().Run()
|
|
} else {
|
|
return shell.Exec("sh", rishPath, "-c", F.ToString(name, " ", strings.Join(args, " "))).Attach().Run()
|
|
}
|
|
}
|
|
|
|
func SetSystemProxy(router adapter.Router, port uint16, isMixed bool) (func() error, error) {
|
|
err := runAndroidShell("settings", "put", "global", "http_proxy", F.ToString("127.0.0.1:", port))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return func() error {
|
|
return runAndroidShell("settings", "put", "global", "http_proxy", ":0")
|
|
}, nil
|
|
}
|