change gui startup, close #476, bump fyne version, fix #479

This commit is contained in:
ffdfgdfg
2020-04-15 19:54:12 +08:00
parent 494d59cc93
commit 805b129c3b
3 changed files with 47 additions and 36 deletions

View File

@@ -32,10 +32,11 @@ func main() {
}
var (
start bool
status = "Start!"
connType = "tcp"
cl = new(client.TRPClient)
start bool
status = "Start!"
connType = "tcp"
cl = new(client.TRPClient)
refreshCh = make(chan struct{})
)
func WidgetScreen() fyne.CanvasObject {
@@ -54,28 +55,8 @@ func makeMainTab() fyne.Widget {
radio := widget.NewRadio([]string{"tcp", "kcp"}, func(s string) { connType = s })
radio.Horizontal = true
refreshCh := make(chan struct{})
button := widget.NewButton(status, func() {
start = !start
if start {
status = "Stop!"
// init the npc
fmt.Println("submit", serverPort.Text, vKey.Text, connType)
sp, vk, ct := loadConfig()
if sp != serverPort.Text || vk != vKey.Text || ct != connType {
saveConfig(serverPort.Text, vKey.Text, connType)
}
cl = client.NewRPClient(serverPort.Text, vKey.Text, connType, "", nil)
go cl.Start()
} else {
// close the npc
status = "Start!"
if cl != nil {
go cl.Close()
cl = nil
}
}
refreshCh <- struct{}{}
onclick(serverPort.Text, vKey.Text, connType)
})
go func() {
for {
@@ -103,6 +84,7 @@ func makeMainTab() fyne.Widget {
vKey.SetText(vk)
connType = ct
radio.SetSelected(ct)
onclick(sp, vk, ct)
}
return widget.NewVBox(
@@ -115,6 +97,29 @@ func makeMainTab() fyne.Widget {
)
}
func onclick(s, v, c string) {
start = !start
if start {
status = "Stop!"
// init the npc
fmt.Println("submit", s, v, c)
sp, vk, ct := loadConfig()
if sp != s || vk != v || ct != c {
saveConfig(s, v, c)
}
cl = client.NewRPClient(s, v, c, "", nil)
go cl.Start()
} else {
// close the npc
status = "Start!"
if cl != nil {
go cl.Close()
cl = nil
}
}
refreshCh <- struct{}{}
}
func getDir() (dir string, err error) {
if runtime.GOOS != "android" {
dir, err = os.UserConfigDir()