From 2cc07c0c16ff6cd4f592fd641301d86f8b6087c3 Mon Sep 17 00:00:00 2001 From: e1732a364fed <75717694+e1732a364fed@users.noreply.github.com> Date: Sat, 1 Jan 2000 00:00:00 +0000 Subject: [PATCH] =?UTF-8?q?gui=E5=B0=86http=E5=92=8Csocks5=E5=9C=B0?= =?UTF-8?q?=E5=9D=80=E7=AB=AF=E5=8F=A3=E5=86=99=E5=85=A5preference?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/verysimple/gui.go | 53 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 48 insertions(+), 5 deletions(-) diff --git a/cmd/verysimple/gui.go b/cmd/verysimple/gui.go index 9b82fae..a04a969 100644 --- a/cmd/verysimple/gui.go +++ b/cmd/verysimple/gui.go @@ -27,6 +27,10 @@ var multilineEntry *ui.MultilineEntry //用于向用户提供一些随机的有 var entriesGroup *ui.Group //父 of multilineEntry type GuiPreference struct { + HttpAddr string `toml:"proxy_http_addr"` + HttpPort string `toml:"proxy_http_port"` + Socks5Addr string `toml:"proxy_socks5_addr"` + Socks5Port string `toml:"proxy_socks5_port"` } func init() { @@ -56,6 +60,12 @@ func init() { }() loadPreferences() + setupDefaultPref() + + utils.PrintStr("Gui Mode entered. \n") + if ce := utils.CanLogInfo("Gui Mode entered"); ce != nil { + ce.Write() + } ui.Main(setupUI) } @@ -69,6 +79,20 @@ func init() { } } +func setupDefaultPref() { + + if gp := currentUserPreference.Gui; gp == nil { + gp = new(GuiPreference) + currentUserPreference.Gui = gp + + gp.HttpAddr = "127.0.0.1" + gp.Socks5Addr = "127.0.0.1" + gp.HttpPort = "10800" + gp.Socks5Port = "10800" + } + +} + func makeBasicControlsPage() ui.Control { vbox := ui.NewVerticalBox() vbox.SetPadded(true) @@ -140,19 +164,38 @@ func makeBasicControlsPage() ui.Control { proxyForm.SetPadded(true) systemProxyGroup.SetChild(proxyForm) - const defaultPort = "10800" - const defaultAddr = "127.0.0.1" - var newProxyToggle = func(form *ui.Form, isSocks5 bool) { + gp := currentUserPreference.Gui + var port = gp.HttpPort + var addr = gp.HttpAddr + str := "http" + if isSocks5 { str = "socks5" + port = gp.Socks5Port + addr = gp.Socks5Addr } addrE := ui.NewEntry() - addrE.SetText(defaultPort) + addrE.SetText(addr) + addrE.OnChanged(func(e *ui.Entry) { + if isSocks5 { + gp.Socks5Addr = e.Text() + } else { + gp.HttpAddr = e.Text() + } + }) + portE := ui.NewEntry() - portE.SetText(defaultAddr) + portE.SetText(port) + portE.OnChanged(func(e *ui.Entry) { + if isSocks5 { + gp.Socks5Port = e.Text() + } else { + gp.HttpPort = e.Text() + } + }) cb := ui.NewCheckbox("系统" + str) cb.OnToggled(func(c *ui.Checkbox) {