mirror of
https://github.com/Baipyrus/ProxySwitcher.git
synced 2024-12-26 04:31:45 +00:00
executing and applying/removing proxy accordingly
This commit is contained in:
parent
60c915b389
commit
e84e0af672
33
proxy/set.go
33
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()
|
||||
}
|
||||
|
@ -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()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user