Skip to content

Commit

Permalink
sysproxy: add status impl
Browse files Browse the repository at this point in the history
  • Loading branch information
5aaee9 committed Apr 16, 2024
1 parent e812fbd commit 17c52b8
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion pkgs/proxy/sysproxy/sysproxy_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,8 @@ import (
"encoding/json"
"errors"
"net"
"os/exec"
"strings"
"unsafe"
)

Expand Down Expand Up @@ -242,7 +244,18 @@ func (p *DarwinSystemProxy) TurnOff() error {
}

func (p *DarwinSystemProxy) Status() (*SystemProxyStatus, error) {
return nil, nil
cmd := exec.Command("scutil", "--proxy")
output, err := cmd.CombinedOutput()
if err != nil {
return nil, err
}

info := strings.ReplaceAll(string(output), " ", "")

status := new(SystemProxyStatus)
status.State = strings.Contains(info, "HTTPEnable:1") || strings.Contains(info, "HTTPSEnable:1")

return status, nil
}

func (p *DarwinSystemProxy) TurnOn(addrport string) error {
Expand Down

0 comments on commit 17c52b8

Please sign in to comment.