添加gui功能,build tag:vsc

This commit is contained in:
e1732a364fed
2000-01-01 00:00:00 +00:00
parent 7ebf20ac1a
commit d9bfd00607
4 changed files with 270 additions and 4 deletions

View File

@@ -29,8 +29,10 @@ var (
disableSplice bool
startPProf bool
startMProf bool
listenURL string //用于命令行模式
dialURL string //用于命令行模式
gui_mode bool
listenURL string //用于命令行模式
dialURL string //用于命令行模式
//jsonMode int
dialTimeoutSecond int
@@ -44,6 +46,7 @@ var (
routingEnv proxy.RoutingEnv
runCli func()
runGui func()
)
const (
@@ -395,6 +398,13 @@ func mainFunc() (result int) {
interactive_mode = false
}
if gui_mode {
if runGui != nil {
runGui()
gui_mode = false
}
}
if nothingRunning() {
utils.Warn(willExitStr)
return
@@ -418,7 +428,7 @@ func hasProxyRunning() bool {
// 是否可以在运行时动态修改配置。如果没有开启 apiServer 开关 也没有 动态修改配置的功能,则当前模式不灵活,无法动态修改
func isFlexible() bool {
return interactive_mode || enableApiServer
return interactive_mode || enableApiServer || gui_mode
}
func noFuture() bool {
@@ -426,5 +436,5 @@ func noFuture() bool {
}
func nothingRunning() bool {
return !hasProxyRunning() && !(interactive_mode || apiServerRunning)
return !hasProxyRunning() && !(interactive_mode || apiServerRunning || gui_mode)
}

252
cmd/verysimple/vsc.go Normal file
View File

@@ -0,0 +1,252 @@
//go:build vsc
package main
// vsc 计划即versyimple client计划使用图形界面. 服务端无需gui所以我们叫client
import (
"log"
"github.com/e1732a364fed/ui"
_ "github.com/e1732a364fed/ui/winmanifest"
)
func init() {
gui_mode = true
runGui = func() {
ui.Main(setupUI)
}
}
var mainwin *ui.Window
func makeBasicControlsPage() ui.Control {
vbox := ui.NewVerticalBox()
vbox.SetPadded(true)
hbox := ui.NewHorizontalBox()
hbox.SetPadded(true)
vbox.Append(hbox, false)
hbox.Append(ui.NewButton("Button"), false)
hbox.Append(ui.NewCheckbox("Checkbox"), false)
vbox.Append(ui.NewLabel("This is a label. Right now, labels can only span one line."), false)
vbox.Append(ui.NewHorizontalSeparator(), false)
group := ui.NewGroup("Entries")
group.SetMargined(true)
vbox.Append(group, true)
group.SetChild(ui.NewNonWrappingMultilineEntry())
entryForm := ui.NewForm()
entryForm.SetPadded(true)
group.SetChild(entryForm)
entryForm.Append("Entry", ui.NewEntry(), false)
entryForm.Append("Password Entry", ui.NewPasswordEntry(), false)
entryForm.Append("Search Entry", ui.NewSearchEntry(), false)
entryForm.Append("Multiline Entry", ui.NewMultilineEntry(), true)
entryForm.Append("Multiline Entry No Wrap", ui.NewNonWrappingMultilineEntry(), true)
return vbox
}
func makeNumbersPage() ui.Control {
hbox := ui.NewHorizontalBox()
hbox.SetPadded(true)
group := ui.NewGroup("Numbers")
group.SetMargined(true)
hbox.Append(group, 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)
group = ui.NewGroup("Lists")
group.SetMargined(true)
hbox.Append(group, true)
vbox = ui.NewVerticalBox()
vbox.SetPadded(true)
group.SetChild(vbox)
cbox := ui.NewCombobox()
cbox.Append("Combobox Item 1")
cbox.Append("Combobox Item 2")
cbox.Append("Combobox Item 3")
vbox.Append(cbox, false)
ecbox := ui.NewEditableCombobox()
ecbox.Append("Editable Item 1")
ecbox.Append("Editable Item 2")
ecbox.Append("Editable Item 3")
vbox.Append(ecbox, false)
rb := ui.NewRadioButtons()
rb.Append("Radio Button 1")
rb.Append("Radio Button 2")
rb.Append("Radio Button 3")
vbox.Append(rb, false)
return hbox
}
func makeDataChoosersPage() ui.Control {
hbox := ui.NewHorizontalBox()
hbox.SetPadded(true)
vbox := ui.NewVerticalBox()
vbox.SetPadded(true)
hbox.Append(vbox, false)
vbox.Append(ui.NewDatePicker(), false)
vbox.Append(ui.NewTimePicker(), false)
vbox.Append(ui.NewDateTimePicker(), false)
vbox.Append(ui.NewFontButton(), false)
vbox.Append(ui.NewColorButton(), false)
hbox.Append(ui.NewVerticalSeparator(), false)
vbox = ui.NewVerticalBox()
vbox.SetPadded(true)
hbox.Append(vbox, true)
grid := ui.NewGrid()
grid.SetPadded(true)
vbox.Append(grid, false)
button := ui.NewButton("Open File")
entry := ui.NewEntry()
entry.SetReadOnly(true)
button.OnClicked(func(*ui.Button) {
filename := ui.OpenFile(mainwin)
if filename == "" {
filename = "(cancelled)"
}
entry.SetText(filename)
})
grid.Append(button,
0, 0, 1, 1,
false, ui.AlignFill, false, ui.AlignFill)
grid.Append(entry,
1, 0, 1, 1,
true, ui.AlignFill, false, ui.AlignFill)
button = ui.NewButton("Save File")
entry2 := ui.NewEntry()
entry2.SetReadOnly(true)
button.OnClicked(func(*ui.Button) {
filename := ui.SaveFile(mainwin)
if filename == "" {
filename = "(cancelled)"
}
entry2.SetText(filename)
})
grid.Append(button,
0, 1, 1, 1,
false, ui.AlignFill, false, ui.AlignFill)
grid.Append(entry2,
1, 1, 1, 1,
true, ui.AlignFill, false, ui.AlignFill)
msggrid := ui.NewGrid()
msggrid.SetPadded(true)
grid.Append(msggrid,
0, 2, 2, 1,
false, ui.AlignCenter, false, ui.AlignStart)
button = ui.NewButton("Message Box")
button.OnClicked(func(*ui.Button) {
ui.MsgBox(mainwin,
"This is a normal message box.",
"More detailed information can be shown here.")
})
msggrid.Append(button,
0, 0, 1, 1,
false, ui.AlignFill, false, ui.AlignFill)
button = ui.NewButton("Error Box")
button.OnClicked(func(*ui.Button) {
ui.MsgBoxError(mainwin,
"This message box describes an error.",
"More detailed information can be shown here.")
})
msggrid.Append(button,
1, 0, 1, 1,
false, ui.AlignFill, false, ui.AlignFill)
return hbox
}
func windowClose(*ui.Window) bool {
return true
}
func setupUI() {
var x = ui.NewMenu("Files")
x.AppendPreferencesItem()
x.AppendAboutItem().OnClicked(func(mi *ui.MenuItem, w *ui.Window) {
log.Println("about")
ui.MsgBox(mainwin,
"verysimple, a very simple proxy",
versionStr()+"\n\nhttps://github.com/e1732a364fed/v2ray_simple/")
})
x.AppendQuitItem()
// x.AppendItem("xxx")
// x.AppendItem("xxx")
// x.AppendItem("xxx")
// x.AppendSeparator()
//var y = ui.NewMenu("Menu2")
//y.AppendItem("verysimple")
mainwin = ui.NewWindow("verysimple", 640, 480, true)
mainwin.OnClosing(func(*ui.Window) bool {
ui.Quit()
return true
})
ui.OnShouldQuit(func() bool {
mainwin.Destroy()
return true
})
tab := ui.NewTab()
mainwin.SetChild(tab)
mainwin.SetMargined(true)
tab.Append("Basic Controls", makeBasicControlsPage())
tab.SetMargined(0, true)
tab.Append("Numbers and Lists", makeNumbersPage())
tab.SetMargined(1, true)
tab.Append("Data Choosers", makeDataChoosersPage())
tab.SetMargined(2, true)
mainwin.Show()
}

2
go.mod
View File

@@ -6,6 +6,7 @@ require (
github.com/BurntSushi/toml v1.2.1
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d
github.com/biter777/countries v1.5.6
github.com/e1732a364fed/ui v0.0.1-alpha.2
github.com/gobwas/ws v1.1.0
github.com/lucas-clemente/quic-go v0.0.0-00010101000000-000000000000
github.com/manifoldco/promptui v0.9.0
@@ -25,6 +26,7 @@ require (
golang.org/x/net v0.0.0-20220909164309-bea034e7d591
golang.org/x/sys v0.1.1-0.20221102194838-fc697a31fa06
gonum.org/v1/gonum v0.11.0
)
require (

2
go.sum
View File

@@ -19,6 +19,8 @@ github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMn
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/e1732a364fed/ui v0.0.1-alpha.2 h1:0E5MiR+JVm/GTfwV7geSiJLA5Y/m5n0EtvjoeCxUplc=
github.com/e1732a364fed/ui v0.0.1-alpha.2/go.mod h1:uK9ryjwA0+3KdICbeXm5IjhKZ+1ZooMVDdTuLaQHpwM=
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 h1:p104kn46Q8WdvHunIJ9dAyjPVtrBPhSr3KT2yUst43I=
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE=
github.com/gobwas/httphead v0.1.0 h1:exrUm0f4YX0L7EBwZHuCF4GDp8aJfVeBrlLQrs6NqWU=