perf: Optimize proxy settings

This commit is contained in:
putyy
2025-05-19 18:03:35 +08:00
parent dc261bb6ce
commit a853f1d991
4 changed files with 12 additions and 12 deletions

View File

@@ -14,7 +14,7 @@
!define INFO_PRODUCTNAME "res-downloader"
!endif
!ifndef INFO_PRODUCTVERSION
!define INFO_PRODUCTVERSION "3.0.5"
!define INFO_PRODUCTVERSION "3.0.6"
!endif
!ifndef INFO_COPYRIGHT
!define INFO_COPYRIGHT "Copyright © 2023"

View File

@@ -121,7 +121,7 @@ func (s *SystemSetup) installCert() (string, error) {
if err != nil {
return "", err
}
output, err := s.runCommand([]string{"sudo", "-S", "security", "add-trusted-cert", "-d", "-r", "trustRoot", "-k", "/Library/Keychains/System.keychain", s.CertFile})
output, err := s.runCommand([]string{"security", "add-trusted-cert", "-d", "-r", "trustRoot", "-k", "/Library/Keychains/System.keychain", s.CertFile})
if err != nil {
return string(output), err
}

View File

@@ -23,13 +23,13 @@ func (s *SystemSetup) getLinuxDistro() (string, error) {
return "", fmt.Errorf("could not determine linux distribution")
}
func (s *SystemSetup) runCommand(args []string) ([]byte, error) {
func (s *SystemSetup) runCommand(args []string, sudo bool) ([]byte, error) {
if len(args) == 0 {
return nil, fmt.Errorf("no command provided")
}
var cmd *exec.Cmd
if s.Password != "" {
if s.Password != "" && sudo {
cmd = exec.Command("sudo", append([]string{"-S"}, args...)...)
cmd.Stdin = bytes.NewReader([]byte(s.Password + "\n"))
} else {
@@ -53,7 +53,7 @@ func (s *SystemSetup) setProxy() error {
var errs strings.Builder
for _, cmd := range commands {
if output, err := s.runCommand(cmd); err != nil {
if output, err := s.runCommand(cmd, false); err != nil {
errs.WriteString(fmt.Sprintf("cmd: %v\noutput: %s\nerr: %s\n", cmd, output, err))
} else {
isSuccess = true
@@ -69,7 +69,7 @@ func (s *SystemSetup) setProxy() error {
func (s *SystemSetup) unsetProxy() error {
cmd := []string{"gsettings", "set", "org.gnome.system.proxy", "mode", "none"}
output, err := s.runCommand(cmd)
output, err := s.runCommand(cmd, false)
if err != nil {
return fmt.Errorf("failed to unset proxy: %s\noutput: %s", err.Error(), string(output))
}
@@ -93,7 +93,7 @@ func (s *SystemSetup) installCert() (string, error) {
if distro == "deepin" {
certDir := "/usr/share/ca-certificates/" + appOnce.AppName
certPath = certDir + "/" + certName
s.runCommand([]string{"mkdir", "-p", certDir})
s.runCommand([]string{"mkdir", "-p", certDir}, true)
} else {
certPath = "/usr/local/share/ca-certificates/" + certName
}
@@ -101,7 +101,7 @@ func (s *SystemSetup) installCert() (string, error) {
var outs, errs strings.Builder
isSuccess := false
if output, err := s.runCommand([]string{"cp", "-f", s.CertFile, certPath}); err != nil {
if output, err := s.runCommand([]string{"cp", "-f", s.CertFile, certPath}, true); err != nil {
errs.WriteString(fmt.Sprintf("copy cert failed: %s\n%s\n", err.Error(), output))
} else {
isSuccess = true
@@ -111,9 +111,9 @@ func (s *SystemSetup) installCert() (string, error) {
if distro == "deepin" {
confPath := "/etc/ca-certificates.conf"
checkCmd := []string{"grep", "-qxF", certName, confPath}
if _, err := s.runCommand(checkCmd); err != nil {
if _, err := s.runCommand(checkCmd, true); err != nil {
echoCmd := []string{"bash", "-c", fmt.Sprintf("echo '%s' >> %s", certName, confPath)}
if output, err := s.runCommand(echoCmd); err != nil {
if output, err := s.runCommand(echoCmd, true); err != nil {
errs.WriteString(fmt.Sprintf("append conf failed: %s\n%s\n", err.Error(), output))
} else {
isSuccess = true
@@ -122,7 +122,7 @@ func (s *SystemSetup) installCert() (string, error) {
}
}
if output, err := s.runCommand([]string{"update-ca-certificates"}); err != nil {
if output, err := s.runCommand([]string{"update-ca-certificates"}, true); err != nil {
errs.WriteString(fmt.Sprintf("update failed: %s\n%s\n", err.Error(), output))
} else {
isSuccess = true

2
go.mod
View File

@@ -10,6 +10,7 @@ require (
github.com/rs/zerolog v1.33.0
github.com/vrischmann/userdir v0.0.0-20151206171402-20f291cebd68
github.com/wailsapp/wails/v2 v2.10.1
golang.org/x/net v0.35.0
golang.org/x/sys v0.30.0
)
@@ -37,6 +38,5 @@ require (
github.com/wailsapp/go-webview2 v1.0.19 // indirect
github.com/wailsapp/mimetype v1.4.1 // indirect
golang.org/x/crypto v0.33.0 // indirect
golang.org/x/net v0.35.0 // indirect
golang.org/x/text v0.22.0 // indirect
)