aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/ui/confview.go
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2019-05-03 11:26:36 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2019-05-03 11:46:46 +0200
commitf268ef204360b354c141a9267256e033ca2ec6c0 (patch)
tree295b4535c8bae427088a2fb6d7bbf2aa6871cc87 /ui/confview.go
parentui: better manage window size (diff)
downloadwireguard-windows-f268ef204360b354c141a9267256e033ca2ec6c0.tar.xz
wireguard-windows-f268ef204360b354c141a9267256e033ca2ec6c0.zip
ui: fix up confview ticker and list sync logic
Diffstat (limited to 'ui/confview.go')
-rw-r--r--ui/confview.go44
1 files changed, 38 insertions, 6 deletions
diff --git a/ui/confview.go b/ui/confview.go
index 6fe02f66..8f7b82c5 100644
--- a/ui/confview.go
+++ b/ui/confview.go
@@ -9,6 +9,7 @@ import (
"fmt"
"strconv"
"strings"
+ "time"
"github.com/lxn/walk"
"github.com/lxn/win"
@@ -65,12 +66,12 @@ type peerView struct {
type ConfView struct {
*walk.ScrollView
- name *walk.GroupBox
- interfaze *interfaceView
- peers map[conf.Key]*peerView
-
+ name *walk.GroupBox
+ interfaze *interfaceView
+ peers map[conf.Key]*peerView
tunnelChangedCB *service.TunnelChangeCallback
tunnel *service.Tunnel
+ updateTicker *time.Ticker
}
func (lsl *labelStatusLine) widgets() (walk.Widget, walk.Widget) {
@@ -409,6 +410,24 @@ func NewConfView(parent walk.Container) (*ConfView, error) {
return nil, err
}
cv.SetDoubleBuffering(true)
+ cv.updateTicker = time.NewTicker(time.Second)
+ go func() {
+ for range cv.updateTicker.C {
+ if cv.tunnel != nil {
+ var state service.TunnelState
+ var config conf.Config
+ if state, _ = cv.tunnel.State(); state == service.TunnelStarted {
+ config, _ = cv.tunnel.RuntimeConfig()
+ }
+ if config.Name == "" {
+ config, _ = cv.tunnel.StoredConfig()
+ }
+ cv.Synchronize(func() {
+ cv.setTunnel(cv.tunnel, &config, state)
+ })
+ }
+ }
+ }()
return cv, nil
}
@@ -417,7 +436,10 @@ func (cv *ConfView) Dispose() {
cv.tunnelChangedCB.Unregister()
cv.tunnelChangedCB = nil
}
-
+ if cv.updateTicker != nil {
+ cv.updateTicker.Stop()
+ cv.updateTicker = nil
+ }
cv.ScrollView.Dispose()
}
@@ -447,10 +469,20 @@ func (cv *ConfView) onTunnelChanged(tunnel *service.Tunnel, state service.Tunnel
cv.interfaze.toggleActive.update(state)
}
})
+ var config conf.Config
+ if state == service.TunnelStarted {
+ config, _ = tunnel.RuntimeConfig()
+ }
+ if config.Name == "" {
+ config, _ = tunnel.StoredConfig()
+ }
+ cv.Synchronize(func() {
+ cv.setTunnel(tunnel, &config, state)
+ })
}
func (cv *ConfView) SetTunnel(tunnel *service.Tunnel) {
- cv.tunnel = tunnel
+ cv.tunnel = tunnel //XXX: This races with the read in the updateTicker, but it's pointer-sized!
var config conf.Config
var state service.TunnelState