2024-08-31 16:01:58 +00:00
|
|
|
package proxy
|
|
|
|
|
2024-08-31 16:27:57 +00:00
|
|
|
import (
|
2024-09-08 19:30:18 +00:00
|
|
|
"log"
|
|
|
|
|
2024-08-31 16:27:57 +00:00
|
|
|
"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()
|
|
|
|
|
2024-08-31 17:13:01 +00:00
|
|
|
// Set system proxy, if not already
|
2024-09-08 19:30:18 +00:00
|
|
|
proxy, err := ReadSystemProxy()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
2024-08-31 16:27:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
configs, _ := util.ReadConfigs()
|
|
|
|
for _, config := range configs {
|
|
|
|
configCmd := config.Name
|
2024-08-31 17:13:01 +00:00
|
|
|
// Use command instead of name, if given
|
2024-08-31 16:27:57 +00:00
|
|
|
if config.Cmd != "" {
|
|
|
|
configCmd = config.Cmd
|
|
|
|
}
|
|
|
|
|
2024-08-31 17:13:01 +00:00
|
|
|
commands := generateCommands(config.Set, configCmd, proxy.Server)
|
|
|
|
util.ExecCmds(commands, stdin)
|
2024-08-31 16:27:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
closeFunc()
|
2024-08-31 16:01:58 +00:00
|
|
|
}
|