diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2019-05-03 11:26:36 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2019-05-03 11:46:46 +0200 |
commit | f268ef204360b354c141a9267256e033ca2ec6c0 (patch) | |
tree | 295b4535c8bae427088a2fb6d7bbf2aa6871cc87 /ui/tunnelspage.go | |
parent | ui: better manage window size (diff) | |
download | wireguard-windows-f268ef204360b354c141a9267256e033ca2ec6c0.tar.xz wireguard-windows-f268ef204360b354c141a9267256e033ca2ec6c0.zip |
ui: fix up confview ticker and list sync logic
Diffstat (limited to '')
-rw-r--r-- | ui/tunnelspage.go | 48 |
1 files changed, 15 insertions, 33 deletions
diff --git a/ui/tunnelspage.go b/ui/tunnelspage.go index 4ae6bd4b..36aa80fa 100644 --- a/ui/tunnelspage.go +++ b/ui/tunnelspage.go @@ -8,16 +8,14 @@ package ui import ( "archive/zip" "fmt" + "github.com/lxn/walk" + "golang.zx2c4.com/wireguard/windows/conf" + "golang.zx2c4.com/wireguard/windows/service" "io/ioutil" "os" "path/filepath" "sort" "strings" - "time" - - "github.com/lxn/walk" - "golang.zx2c4.com/wireguard/windows/conf" - "golang.zx2c4.com/wireguard/windows/service" ) type TunnelsPage struct { @@ -58,8 +56,6 @@ func NewTunnelsPage() (*TunnelsPage, error) { if tp.tunnelsView, err = NewListView(listContainer); err != nil { return nil, err } - tp.tunnelsView.ItemActivated().Attach(tp.onTunnelsViewItemActivated) - tp.tunnelsView.CurrentIndexChanged().Attach(tp.updateConfView) // HACK: Because of https://github.com/lxn/walk/issues/481 // we need to put the ToolBar into its own Composite. @@ -121,7 +117,7 @@ func NewTunnelsPage() (*TunnelsPage, error) { exportAction.Triggered().Attach(tp.onExportTunnels) listToolbar.Actions().Add(exportAction) - listContainerWidth := listToolbar.MinSizeHint().Width + tp.DPI() / 10 // TODO: calculate these margins correctly instead + listContainerWidth := listToolbar.MinSizeHint().Width + tp.DPI()/10 // TODO: calculate these margins correctly instead listContainer.SetMinMaxSize(walk.Size{listContainerWidth, 0}, walk.Size{listContainerWidth, 0}) tp.currentTunnelContainer, _ = walk.NewComposite(tp) @@ -131,9 +127,9 @@ func NewTunnelsPage() (*TunnelsPage, error) { tp.fillerContainer, _ = walk.NewComposite(tp) tp.fillerContainer.SetVisible(false) - tp.fillerContainer.SetLayout(walk.NewHBoxLayout()) - tp.fillerContainer.Layout().SetMargins(walk.Margins{}) - walk.NewHSpacer(tp.fillerContainer) + hlayout = walk.NewHBoxLayout() + hlayout.SetMargins(walk.Margins{}) + tp.fillerContainer.SetLayout(hlayout) tp.fillerButton, _ = walk.NewPushButton(tp.fillerContainer) buttonWidth := tp.DPI() * 2 //TODO: Use dynamic DPI tp.fillerButton.SetMinMaxSize(walk.Size{buttonWidth, 0}, walk.Size{buttonWidth, 0}) @@ -142,25 +138,9 @@ func NewTunnelsPage() (*TunnelsPage, error) { tp.fillerHandler() } }) - walk.NewHSpacer(tp.fillerContainer) - - //TODO: expose walk.TableView.itemCountChangedPublisher.Event() - tp.tunnelsView.Property("ItemCount").Changed().Attach(tp.onTunnelsChanged) - tp.onTunnelsChanged() - tp.tunnelsView.SelectedIndexesChanged().Attach(tp.onSelectedTunnelsChanged) tp.confView, _ = NewConfView(tp.currentTunnelContainer) - updateConfViewTicker := time.NewTicker(time.Second) - tp.Disposing().Attach(updateConfViewTicker.Stop) - go func() { - for range updateConfViewTicker.C { - tp.Synchronize(func() { - tp.updateConfView() - }) - } - }() - controlsContainer, _ := walk.NewComposite(tp.currentTunnelContainer) controlsContainer.SetLayout(walk.NewHBoxLayout()) controlsContainer.Layout().SetMargins(walk.Margins{}) @@ -175,18 +155,20 @@ func NewTunnelsPage() (*TunnelsPage, error) { editTunnel.SetText("Edit") editTunnel.Clicked().Attach(tp.onEditTunnel) - tp.tunnelsView.SetCurrentIndex(0) - disposables.Spare() + //TODO: expose walk.TableView.itemCountChangedPublisher.Event() + tp.tunnelsView.Property("ItemCount").Changed().Attach(tp.onTunnelsChanged) + tp.tunnelsView.SelectedIndexesChanged().Attach(tp.onSelectedTunnelsChanged) + tp.tunnelsView.ItemActivated().Attach(tp.onTunnelsViewItemActivated) + tp.tunnelsView.CurrentIndexChanged().Attach(tp.updateConfView) + tp.tunnelsView.Load(false) + tp.onTunnelsChanged() + return tp, nil } func (tp *TunnelsPage) updateConfView() { - if !tp.Visible() || !tp.currentTunnelContainer.Visible() { - return - } - tp.confView.SetTunnel(tp.tunnelsView.CurrentTunnel()) } |