2024-08-31 16:01:58 +00:00
|
|
|
package proxy
|
|
|
|
|
2024-08-31 16:27:57 +00:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/Baipyrus/ProxySwitcher/util"
|
|
|
|
)
|
|
|
|
|
2024-08-31 16:01:58 +00:00
|
|
|
func Set() {
|
2024-08-31 16:27:57 +00:00
|
|
|
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()
|
2024-08-31 16:01:58 +00:00
|
|
|
}
|