aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/ui/manage_tunnels.go
diff options
context:
space:
mode:
authorAlexander Neumann <alexander.neumann@picos-software.com>2019-04-23 10:31:05 +0200
committerAlexander Neumann <alexander.neumann@picos-software.com>2019-04-23 11:05:00 +0200
commit6fb2679fba7f315c0f8ff7e9f7ab7c888fa6cb9e (patch)
tree51a0103123ac611d21a1244fc08b9f2c1a2fed3b /ui/manage_tunnels.go
parentui: some log dialog improvements (diff)
downloadwireguard-windows-6fb2679fba7f315c0f8ff7e9f7ab7c888fa6cb9e.tar.xz
wireguard-windows-6fb2679fba7f315c0f8ff7e9f7ab7c888fa6cb9e.zip
ui: some cleanup in ManageTunnelsWindow
Signed-off-by: Alexander Neumann <alexander.neumann@picos-software.com> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to '')
-rw-r--r--ui/manage_tunnels.go57
1 files changed, 22 insertions, 35 deletions
diff --git a/ui/manage_tunnels.go b/ui/manage_tunnels.go
index 353b4f68..f2719ff5 100644
--- a/ui/manage_tunnels.go
+++ b/ui/manage_tunnels.go
@@ -24,8 +24,7 @@ import (
type ManageTunnelsWindow struct {
*walk.MainWindow
- icon *walk.Icon
-
+ icon *walk.Icon
logger *ringlogger.Ringlogger
tunnelTracker *TunnelTracker
tunnelsView *TunnelsView
@@ -37,6 +36,9 @@ type ManageTunnelsWindow struct {
func NewManageTunnelsWindow(icon *walk.Icon, logger *ringlogger.Ringlogger) (*ManageTunnelsWindow, error) {
var err error
+ var disposables walk.Disposables
+ defer disposables.Treat()
+
mtw := &ManageTunnelsWindow{
icon: icon,
logger: logger,
@@ -45,15 +47,13 @@ func NewManageTunnelsWindow(icon *walk.Icon, logger *ringlogger.Ringlogger) (*Ma
if err != nil {
return nil, err
}
+ disposables.Add(mtw)
- return mtw, mtw.setup()
-}
-
-func (mtw *ManageTunnelsWindow) setup() error {
mtw.SetIcon(mtw.icon)
+ mtw.SetTitle("Manage WireGuard Tunnels")
font, err := walk.NewFont("Segoe UI", 9, 0)
if err != nil {
- return err
+ return nil, err
}
mtw.AddDisposable(font)
mtw.SetFont(font)
@@ -63,6 +63,11 @@ func (mtw *ManageTunnelsWindow) setup() error {
// "Close to tray" instead of exiting application
onQuit()
})
+ mtw.Starting().Attach(func() {
+ mtw.updateConfView()
+ win.SetForegroundWindow(mtw.Handle())
+ win.BringWindowToTop(mtw.Handle())
+ })
splitter, _ := walk.NewHSplitter(mtw)
splitter.SetSuspended(true)
@@ -79,10 +84,6 @@ func (mtw *ManageTunnelsWindow) setup() error {
mtw.tunnelsView.ItemActivated().Attach(mtw.onEditTunnel)
mtw.tunnelsView.CurrentIndexChanged().Attach(mtw.updateConfView)
- service.IPCClientRegisterTunnelChange(func(tunnel *service.Tunnel, state service.TunnelState, err error) {
- mtw.tunnelsView.Invalidate()
- })
-
// ToolBar actions
{
// HACK: Because of https://github.com/lxn/walk/issues/481
@@ -108,8 +109,8 @@ func (mtw *ManageTunnelsWindow) setup() error {
exportTunnelsAction.SetText("Export tunnels to zip...")
exportTunnelsAction.Triggered().Attach(mtw.onExportTunnels)
- // TODO: Add this to the dispose array (AddDisposable)
addMenu, _ := walk.NewMenu()
+ mtw.AddDisposable(addMenu)
addMenu.Actions().Add(addAction)
addMenu.Actions().Add(importAction)
addMenuAction, _ := tunnelsToolBar.Actions().AddMenu(addMenu)
@@ -121,6 +122,7 @@ func (mtw *ManageTunnelsWindow) setup() error {
deleteAction.Triggered().Attach(mtw.onDelete)
settingsMenu, _ := walk.NewMenu()
+ mtw.AddDisposable(settingsMenu)
settingsMenu.Actions().Add(viewLogAction)
settingsMenu.Actions().Add(exportTunnelsAction)
settingsMenuAction, _ := tunnelsToolBar.Actions().AddMenu(settingsMenu)
@@ -131,28 +133,17 @@ func (mtw *ManageTunnelsWindow) setup() error {
currentTunnelContainer.SetLayout(walk.NewVBoxLayout())
mtw.confView, _ = NewConfView(currentTunnelContainer)
+
+ updateConfViewTicker := time.NewTicker(time.Second)
+ mtw.Disposing().Attach(updateConfViewTicker.Stop)
go func() {
- // TODO: teardown in Dispose()
- t := time.NewTicker(time.Second)
- for range t.C {
+ for range updateConfViewTicker.C {
mtw.Synchronize(func() {
mtw.updateConfView()
})
}
}()
- // TODO: Find a better place for this?
- // logfile, err := service.IPCClientLogFilePath()
- // var logger *ringlogger.Ringlogger
- // if err == nil {
- // logger, err = ringlogger.NewRinglogger(logfile, "GUI")
- // }
- // if err != nil {
- // walk.MsgBox(nil, "Unable to initialize logging", fmt.Sprintf("%v\n\nFile: %s", err, logfile), walk.MsgBoxIconError)
- // return err
- // }
- // NewLogView(currentTunnelContainer, logger)
-
controlsContainer, _ := walk.NewComposite(currentTunnelContainer)
controlsContainer.SetLayout(walk.NewHBoxLayout())
controlsContainer.Layout().SetMargins(walk.Margins{})
@@ -167,15 +158,11 @@ func (mtw *ManageTunnelsWindow) setup() error {
editTunnel.SetText("Edit")
editTunnel.Clicked().Attach(mtw.onEditTunnel)
- return nil
-}
+ mtw.tunnelsView.SetCurrentIndex(0)
+
+ disposables.Spare()
-func (mtw *ManageTunnelsWindow) Show() {
- mtw.MainWindow.Show()
- // TODO: Upstream lxn/walk has VisibleChanged()
- mtw.updateConfView()
- win.SetForegroundWindow(mtw.Handle())
- win.BringWindowToTop(mtw.Handle())
+ return mtw, nil
}
func (mtw *ManageTunnelsWindow) TunnelTracker() *TunnelTracker {