aboutsummaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2019-06-03 12:15:25 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2019-06-07 11:31:53 +0200
commit909668e8130aa25f3913dcd115ea8cc39ea70409 (patch)
treecad52033fb26e9f05d06dec15a6461bc4e658f69 /ui
parenttunnel: fix formatting (diff)
downloadwireguard-windows-909668e8130aa25f3913dcd115ea8cc39ea70409.tar.xz
wireguard-windows-909668e8130aa25f3913dcd115ea8cc39ea70409.zip
ui: cache last observed state
Sometimes State() is out of sync with the notifications when a service removal is pending. This unifies that, and also removes IPC from the main thread.
Diffstat (limited to 'ui')
-rw-r--r--ui/listview.go20
1 files changed, 15 insertions, 5 deletions
diff --git a/ui/listview.go b/ui/listview.go
index ebdf3260..71e5df48 100644
--- a/ui/listview.go
+++ b/ui/listview.go
@@ -20,7 +20,8 @@ type ListModel struct {
walk.TableModelBase
walk.SorterBase
- tunnels []manager.Tunnel
+ tunnels []manager.Tunnel
+ lastObservedState map[manager.Tunnel]manager.TunnelState
}
func (t *ListModel) RowCount() int {
@@ -62,6 +63,7 @@ func NewListView(parent walk.Container) (*ListView, error) {
tv.SetDoubleBuffering(true)
model := new(ListModel)
+ model.lastObservedState = make(map[manager.Tunnel]manager.TunnelState)
tv.SetModel(model)
tv.SetLastColumnStretched(true)
tv.SetHeaderHidden(true)
@@ -113,10 +115,16 @@ func (tv *ListView) StyleCell(style *walk.CellStyle) {
b.Width -= b.Height
canvas.DrawText(tunnel.Name, tv.Font(), style.TextColor, b, walk.TextVCenter|walk.TextSingleLine)
- //TODO: don't make an IPC call from the drawing thread like this!
- state, err := tunnel.State()
- if err != nil {
- return
+ var state manager.TunnelState
+ var ok bool
+ state, ok = tv.model.lastObservedState[tv.model.tunnels[row]]
+ if !ok {
+ var err error
+ state, err = tunnel.State()
+ if err != nil {
+ return
+ }
+ tv.model.lastObservedState[tv.model.tunnels[row]] = state
}
const margin = 2
b.X = margin
@@ -150,6 +158,7 @@ func (tv *ListView) onTunnelChange(tunnel *manager.Tunnel, state manager.TunnelS
}
if idx != -1 {
+ tv.model.lastObservedState[tv.model.tunnels[idx]] = state
tv.model.PublishRowChanged(idx)
return
}
@@ -193,6 +202,7 @@ func (tv *ListView) Load(asyncUI bool) {
if t.Name == tunnel.Name {
tv.model.tunnels = append(tv.model.tunnels[:i], tv.model.tunnels[i+1:]...)
tv.model.PublishRowsRemoved(i, i) //TODO: Do we have to call that everytime or can we pass a range?
+ delete(tv.model.lastObservedState, t)
break
}
}