2024-08-31 16:01:58 +00:00
|
|
|
package proxy
|
|
|
|
|
2024-08-31 16:27:57 +00:00
|
|
|
import (
|
|
|
|
"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-09-12 21:19:57 +00:00
|
|
|
proxy, _ := ReadSystemProxy()
|
2024-08-31 17:13:01 +00:00
|
|
|
// Set system proxy, if not already
|
2024-09-12 21:19:57 +00:00
|
|
|
if !proxy.Enabled {
|
|
|
|
SetSystemProxy(true)
|
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
|
|
|
}
|