Skip to content

Commit

Permalink
feat(core): 设置系统代理时同时设置环境变量
Browse files Browse the repository at this point in the history
  • Loading branch information
junlongzzz committed Dec 21, 2024
1 parent 3065f8a commit ca7aef1
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
13 changes: 12 additions & 1 deletion core.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,18 @@ func isCoreRunning() bool {

// 设置系统代理为core配置的代理
func setCoreProxy() bool {
return setProxyWithDefaultBypass(true, fmt.Sprintf("127.0.0.1:%d", coreConfig.HttpProxyPort))
set := setProxyWithDefaultBypass(true, fmt.Sprintf("127.0.0.1:%d", coreConfig.HttpProxyPort))
if set {
proxyUrl := fmt.Sprintf("http://127.0.0.1:%d", coreConfig.HttpProxyPort)
// 设置环境变量
_ = os.Setenv("HTTP_PROXY", proxyUrl)
_ = os.Setenv("HTTPS_PROXY", proxyUrl)
} else {
// 恢复环境变量
_ = os.Unsetenv("HTTP_PROXY")
_ = os.Unsetenv("HTTPS_PROXY")
}
return set
}

// 获取core版本号
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.23

require (
github.com/energye/systray v1.0.2
golang.org/x/sys v0.27.0
golang.org/x/sys v0.28.0
gopkg.in/yaml.v3 v3.0.1
)

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ github.com/godbus/dbus/v5 v5.1.0/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5x
github.com/tevino/abool v0.0.0-20220530134649-2bfc934cb23c h1:coVla7zpsycc+kA9NXpcvv2E4I7+ii6L5hZO2S6C3kw=
github.com/tevino/abool v0.0.0-20220530134649-2bfc934cb23c/go.mod h1:qc66Pna1RiIsPa7O4Egxxs9OqkuxDX55zznh9K07Tzg=
golang.org/x/sys v0.0.0-20200515095857-1151b9dac4a9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.27.0 h1:wBqf8DvsY9Y/2P8gAfPDEYNuS30J4lPHJxXSb/nJZ+s=
golang.org/x/sys v0.27.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
Expand Down
2 changes: 1 addition & 1 deletion tray.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func onReady() {

systray.AddMenuItem("Check Update", "Check Update").Click(func() {
go func() {
resp, err := http.Get(fmt.Sprintf("https://ghp.ci/%s/releases/latest/download/version.txt", AppGitHubRepo))
resp, err := http.Get(fmt.Sprintf("%s/releases/latest/download/version.txt", AppGitHubRepo))
if err != nil {
messageBoxAlert(AppName, fmt.Sprintf("Failed to check update: %v", err))
return
Expand Down

0 comments on commit ca7aef1

Please sign in to comment.