arblant
firefox-vpn-client / core / internal / desktop / sysproxy_darwin.go
sysproxy_darwin.go41 lines · 1.1 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
//go:build darwin

package desktop

import (
	"os"
	"os/exec"
	"path/filepath"
	"strings"
)

// The macOS proxy setting of every enabled network service, through
// networksetup (networksetup.go).
var macNetworkSetup = networkSetup{
	run: func(args ...string) (string, error) {
		out, err := exec.Command("/usr/sbin/networksetup", args...).CombinedOutput()
		return strings.TrimSpace(string(out)), err
	},
	backup: func() (string, error) {
		dir, err := os.UserConfigDir()
		if err != nil {
			return "", err
		}
		return filepath.Join(dir, "Firefox VPN Client", "previous-proxy.json"), nil
	},
}

func systemProxySupported() bool {
	_, err := os.Stat("/usr/sbin/networksetup")
	return err == nil
}

func setSystemProxy(server string) error { return macNetworkSetup.set(server) }

func restoreSystemProxy(server string) error { return macNetworkSetup.restore(server) }

func clearSystemProxy() error { return macNetworkSetup.clear() }

// systemProxyTaken: another program's setting is not looked for on macOS,
// where each network service has its own.
func systemProxyTaken(string) (bool, string) { return false, "" }