basic proxy error handling; exit on read proxy error

This commit is contained in:
Baipyrus 2024-09-08 21:30:18 +02:00
parent 306511be13
commit 7b09ac0cda
3 changed files with 21 additions and 5 deletions

View File

@ -2,6 +2,7 @@ package proxy
import ( import (
"fmt" "fmt"
"log"
"strings" "strings"
"github.com/Baipyrus/ProxySwitcher/util" "github.com/Baipyrus/ProxySwitcher/util"
@ -20,7 +21,12 @@ func mapCmdsToStr(commands []*util.Command) string {
} }
func Debug() { func Debug() {
proxy, _ := ReadSystemProxy() proxy, err := ReadSystemProxy()
if err != nil {
log.Fatal(err)
}
fmt.Println("\nSystem Proxy:") fmt.Println("\nSystem Proxy:")
fmt.Printf("Enabled: %t\n", proxy.Enabled) fmt.Printf("Enabled: %t\n", proxy.Enabled)
fmt.Printf("Server: %s\n\n", proxy.Server) fmt.Printf("Server: %s\n\n", proxy.Server)

View File

@ -1,16 +1,19 @@
package proxy package proxy
import ( import (
"log"
"github.com/Baipyrus/ProxySwitcher/util" "github.com/Baipyrus/ProxySwitcher/util"
) )
func Set() { func Set() {
stdin, closeFunc, _ := util.ReadyCmd() stdin, closeFunc, _ := util.ReadyCmd()
proxy, _ := ReadSystemProxy()
// Set system proxy, if not already // Set system proxy, if not already
if !proxy.Enabled { proxy, err := ReadSystemProxy()
SetSystemProxy(true)
if err != nil {
log.Fatal(err)
} }
configs, _ := util.ReadConfigs() configs, _ := util.ReadConfigs()

View File

@ -1,6 +1,8 @@
package proxy package proxy
import ( import (
"log"
"github.com/Baipyrus/ProxySwitcher/util" "github.com/Baipyrus/ProxySwitcher/util"
) )
@ -8,7 +10,12 @@ func Unset() {
stdin, closeFunc, _ := util.ReadyCmd() stdin, closeFunc, _ := util.ReadyCmd()
// Unset system proxy, if not already // Unset system proxy, if not already
proxy, _ := ReadSystemProxy() proxy, err := ReadSystemProxy()
if err != nil {
log.Fatal(err)
}
if proxy.Enabled { if proxy.Enabled {
SetSystemProxy(false) SetSystemProxy(false)
} }