修订gui代码.可实时调节dial的mux开关,和hy的手动挡数值

This commit is contained in:
e1732a364fed
2000-01-01 00:00:00 +00:00
parent 59e098ded5
commit 1c89b2fad9
5 changed files with 222 additions and 96 deletions

View File

@@ -422,86 +422,6 @@ func makeBasicControlsPage() ui.Control {
return vbox
}
func makeConfPage() ui.Control {
result := ui.NewHorizontalBox()
group := ui.NewGroup("Numbers")
group2 := ui.NewGroup("Lists")
result.Append(group, true)
result.Append(group2, true)
result.SetPadded(true)
group.SetMargined(true)
group2.SetMargined(true)
{
vbox := ui.NewVerticalBox()
vbox.SetPadded(true)
group.SetChild(vbox)
spinbox := ui.NewSpinbox(0, 100)
slider := ui.NewSlider(0, 100)
pbar := ui.NewProgressBar()
spinbox.OnChanged(func(*ui.Spinbox) {
slider.SetValue(spinbox.Value())
pbar.SetValue(spinbox.Value())
})
slider.OnChanged(func(*ui.Slider) {
spinbox.SetValue(slider.Value())
pbar.SetValue(slider.Value())
})
vbox.Append(spinbox, false)
vbox.Append(slider, false)
vbox.Append(pbar, false)
// ip := ui.NewProgressBar()
// ip.SetValue(-1)
// vbox.Append(ip, false)
}
vbox := ui.NewVerticalBox()
group2.SetChild(vbox)
vbox.SetPadded(true)
hbox2 := ui.NewHorizontalBox()
vbox.Append(hbox2, false)
hbox2.Append(ui.NewLabel("Listen"), false)
cbox := ui.NewCombobox()
hbox2.Append(cbox, true)
// cbox.Append("Combobox Item 1")
// cbox.Append("Combobox Item 2")
// cbox.Append("Combobox Item 3")
hbox2 = ui.NewHorizontalBox()
vbox.Append(hbox2, false)
hbox2.Append(ui.NewLabel("Dial"), false)
cbox = ui.NewCombobox()
hbox2.Append(cbox, true)
ecbox := ui.NewEditableCombobox()
vbox.Append(ecbox, false)
ecbox.Append("Editable Item 1")
ecbox.Append("Editable Item 2")
ecbox.Append("Editable Item 3")
rb := ui.NewRadioButtons()
rb.Append("Radio Button 1")
rb.Append("Radio Button 2")
rb.Append("Radio Button 3")
vbox.Append(rb, false)
return result
}
func windowClose(*ui.Window) bool {
return true
}
@@ -529,7 +449,8 @@ func setupUI() {
mainwin.SetMargined(true)
tab.Append("基础控制", makeBasicControlsPage())
tab.Append("配置控制", makeConfPage())
tab.Append("代理控制", makeConfPage())
tab.Append("app控制", makeAppPage())
//tab.Append("Data Choosers", makeDataChoosersPage())
for i := 0; i < tab.NumPages(); i++ {

153
cmd/verysimple/gui_conf.go Normal file
View File

@@ -0,0 +1,153 @@
//go:build gui
package main
import (
"os"
"github.com/e1732a364fed/ui"
)
var appVboxExtra []func(*ui.Box)
func makeAppPage() ui.Control {
result := ui.NewHorizontalBox()
group := ui.NewGroup("Numbers")
result.Append(group, true)
group.SetMargined(true)
{
vbox := ui.NewVerticalBox()
vbox.SetPadded(true)
group.SetChild(vbox)
// ip := ui.NewProgressBar()
// ip.SetValue(-1)
// vbox.Append(ip, false)
if len(appVboxExtra) > 0 {
for _, f := range appVboxExtra {
f(vbox)
}
}
}
return result
}
func makeConfPage() ui.Control {
result := ui.NewHorizontalBox()
group1 := ui.NewGroup("Listen")
group2 := ui.NewGroup("Dial")
result.Append(group1, true)
result.Append(group2, true)
result.SetPadded(true)
group1.SetMargined(true)
group2.SetMargined(true)
vbox1 := ui.NewVerticalBox()
group1.SetChild(vbox1)
vbox1.SetPadded(true)
hbox2 := ui.NewHorizontalBox()
vbox1.Append(hbox2, false)
hbox2.Append(ui.NewLabel("Listen"), false)
listenCbox := ui.NewCombobox()
hbox2.Append(listenCbox, true)
sc := mainM.DumpStandardConf()
for i, lc := range sc.Listen {
n := lc.Tag
if n == "" {
n = "(no tag)"
}
listenCbox.Append(n)
listenCbox.SetSelected(i)
}
vbox2 := ui.NewVerticalBox()
group2.SetChild(vbox2)
hbox2 = ui.NewHorizontalBox()
vbox2.Append(hbox2, false)
hbox2.Append(ui.NewLabel("Dial"), false)
dialCbox := ui.NewCombobox()
hbox2.Append(dialCbox, true)
curSelectedDial := -1
var update func(shouldChange bool)
for i, dc := range sc.Dial {
n := dc.Tag
if n == "" {
n = "(no tag)"
}
dialCbox.Append(n)
curSelectedDial = i
dialCbox.SetSelected(curSelectedDial)
}
dialCbox.OnSelected(func(c *ui.Combobox) {
curSelectedDial = dialCbox.Selected()
update(false)
})
muxC := ui.NewCheckbox("mux")
if curSelectedDial >= 0 {
muxC.SetChecked(sc.Dial[curSelectedDial].Mux)
}
vbox2.Append(muxC, false)
muxC.OnToggled(func(c *ui.Checkbox) {
sc.Dial[curSelectedDial].Mux = muxC.Checked()
update(true)
})
update = func(shouldChange bool) {
muxC.SetChecked(sc.Dial[curSelectedDial].Mux)
if shouldChange {
var shouldStart = false
if mainM.IsRunning() {
mainM.Stop()
shouldStart = true
}
mainM.RemoveAllClient()
mainM.LoadDialConf(sc.Dial)
if shouldStart {
mainM.Start()
}
mainM.PrintAllStateForHuman(os.Stdout)
}
}
// ecbox := ui.NewEditableCombobox()
// vbox.Append(ecbox, false)
// ecbox.Append("Editable Item 1")
// ecbox.Append("Editable Item 2")
// ecbox.Append("Editable Item 3")
// rb := ui.NewRadioButtons()
// rb.Append("Radio Button 1")
// rb.Append("Radio Button 2")
// rb.Append("Radio Button 3")
// vbox.Append(rb, false)
return result
}

View File

@@ -0,0 +1,46 @@
//go:build gui && !noquic
package main
import (
"github.com/e1732a364fed/ui"
"github.com/e1732a364fed/v2ray_simple/advLayer/quic"
"github.com/e1732a364fed/v2ray_simple/utils"
"go.uber.org/zap"
)
func init() {
appVboxExtra = append(appVboxExtra, func(vbox *ui.Box) {
//quic 手动挡调节, 0.2 ~ 1.5 映射到 0 100
spinbox := ui.NewSpinbox(0, 100)
slider := ui.NewSlider(0, 100)
vbox.Append(ui.NewLabel("调节hysteria手动挡 (数值越大, 速度越慢, 数值越小, 速度越快)"), false)
setQuicManual := func(num float64) {
quic.TheCustomRate = 0.2 + num/100*(1.5-0.2)
if ce := utils.CanLogInfo("Manually Adjust Quic Hysteria Custom Rate"); ce != nil {
ce.Write(zap.Float64("rate", quic.TheCustomRate))
}
}
spinbox.OnChanged(func(*ui.Spinbox) {
v := spinbox.Value()
slider.SetValue(v)
setQuicManual(float64(v))
})
slider.OnChanged(func(*ui.Slider) {
v := slider.Value()
spinbox.SetValue(v)
setQuicManual(float64(v))
})
curV := int((quic.TheCustomRate - 0.2) * 100)
slider.SetValue(curV)
spinbox.SetValue(curV)
vbox.Append(spinbox, false)
vbox.Append(slider, false)
})
}

View File

@@ -85,11 +85,20 @@ func (m *M) LoadListenConf(conf []*proxy.ListenConf, hot bool) (ok bool) {
return
}
func (m *M) RemoveAllClient() {
count := m.ClientCount()
for i := 0; i < count; i++ {
m.HotDeleteClient(0)
}
}
// delete and stop the client
func (m *M) HotDeleteClient(index int) {
if index < 0 || index >= len(m.allClients) {
return
}
doomedClient := m.allClients[index]
m.routingEnv.DelClient(doomedClient.GetTag())

View File

@@ -200,6 +200,16 @@ func (m *M) HasProxyRunning() bool {
return len(m.listenCloserList) > 0
}
func (m *M) printAllState_2(w io.Writer) {
for i, s := range m.allServers {
fmt.Fprintln(w, "inServer", i, proxy.GetVSI_url(s, ""))
}
for i, c := range m.allClients {
fmt.Fprintln(w, "outClient", i, proxy.GetVSI_url(c, ""))
}
}
func (m *M) PrintAllState(w io.Writer) {
if w == nil {
w = os.Stdout
@@ -208,14 +218,7 @@ func (m *M) PrintAllState(w io.Writer) {
fmt.Fprintln(w, "allDownloadBytesSinceStart", m.AllDownloadBytesSinceStart)
fmt.Fprintln(w, "allUploadBytesSinceStart", m.AllUploadBytesSinceStart)
for i, s := range m.allServers {
fmt.Fprintln(w, "inServer", i, proxy.GetVSI_url(s, ""))
}
for i, c := range m.allClients {
fmt.Fprintln(w, "outClient", i, proxy.GetVSI_url(c, ""))
}
m.printAllState_2(w)
}
// mimic PrintAllState
@@ -227,12 +230,6 @@ func (m *M) PrintAllStateForHuman(w io.Writer) {
fmt.Fprintln(w, "allDownloadBytesSinceStart", humanize.Bytes(m.AllDownloadBytesSinceStart))
fmt.Fprintln(w, "allUploadBytesSinceStart", humanize.Bytes(m.AllUploadBytesSinceStart))
for i, s := range m.allServers {
fmt.Fprintln(w, "inServer", i, proxy.GetVSI_url(s, ""))
}
for i, c := range m.allClients {
fmt.Fprintln(w, "outClient", i, proxy.GetVSI_url(c, ""))
}
m.printAllState_2(w)
}