From e84e0af67215046dbad6293036bf23564b67ecbc Mon Sep 17 00:00:00 2001 From: Baipyrus Date: Sat, 31 Aug 2024 18:27:57 +0200 Subject: [PATCH] executing and applying/removing proxy accordingly --- proxy/set.go | 33 +++++++++++++++++++++++++++++++++ proxy/unset.go | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) diff --git a/proxy/set.go b/proxy/set.go index 255ae78..618b222 100644 --- a/proxy/set.go +++ b/proxy/set.go @@ -1,4 +1,37 @@ package proxy +import ( + "fmt" + "strings" + + "github.com/Baipyrus/ProxySwitcher/util" +) + func Set() { + stdin, closeFunc, _ := util.ReadyCmd() + + proxy, _ := ReadSystemProxy() + if !proxy.Enabled { + SetSystemProxy(true) + } + + configs, _ := util.ReadConfigs() + for _, config := range configs { + configCmd := config.Name + if config.Cmd != "" { + configCmd = config.Cmd + } + + commands := getVariants(config.Set, configCmd, proxy.Server) + + for _, command := range commands { + cmdArgs := strings.Join(command.Arguments, " ") + cmdStr := fmt.Sprintf("%s %s", command.Name, cmdArgs) + + fmt.Printf("%s\n", cmdStr) + fmt.Fprintln(*stdin, cmdStr) + } + } + + closeFunc() } diff --git a/proxy/unset.go b/proxy/unset.go index f904a88..af05745 100644 --- a/proxy/unset.go +++ b/proxy/unset.go @@ -1,3 +1,37 @@ package proxy +import ( + "fmt" + "strings" + + "github.com/Baipyrus/ProxySwitcher/util" +) + +func Unset() { + stdin, closeFunc, _ := util.ReadyCmd() + + proxy, _ := ReadSystemProxy() + if proxy.Enabled { + SetSystemProxy(false) + } + + configs, _ := util.ReadConfigs() + for _, config := range configs { + configCmd := config.Name + if config.Cmd != "" { + configCmd = config.Cmd + } + + commands := getVariants(config.Unset, configCmd, "") + + for _, command := range commands { + cmdArgs := strings.Join(command.Arguments, " ") + cmdStr := fmt.Sprintf("%s %s", command.Name, cmdArgs) + + fmt.Printf("%s\n", cmdStr) + fmt.Fprintln(*stdin, cmdStr) + } + } + + closeFunc() }