aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2019-03-04 22:57:18 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2019-03-05 05:36:21 +0100
commitd23d0db502a4194bfd842540d0fdd9d27af1b047 (patch)
treee1208458475272b92fb3bf4568a93d9bf9f17a11
parentui: add temporary confview disgusting kludge (diff)
downloadwireguard-windows-d23d0db502a4194bfd842540d0fdd9d27af1b047.tar.xz
wireguard-windows-d23d0db502a4194bfd842540d0fdd9d27af1b047.zip
ui: show runtime config
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
-rw-r--r--ui/ui.go41
1 files changed, 40 insertions, 1 deletions
diff --git a/ui/ui.go b/ui/ui.go
index f5815ec6..05a7f0b8 100644
--- a/ui/ui.go
+++ b/ui/ui.go
@@ -15,6 +15,7 @@ import (
"golang.zx2c4.com/wireguard/windows/service"
"golang.zx2c4.com/wireguard/windows/ui/syntax"
"os"
+ "time"
)
const demoConfig = `[Interface]
@@ -81,9 +82,42 @@ func RunUI() {
})
se.SetText(demoConfig)
+ cv, _ := syntax.NewConfView(mw)
+ cv.SetVisible(false)
+ cv.SetEnabled(false)
+
+ var runningTunnel *service.Tunnel
+ updateConfView := func() {
+ tun := runningTunnel
+ if tun == nil || !mw.Visible() || !cv.Visible() {
+ return
+ }
+ conf, err := tun.RuntimeConfig()
+ if err != nil {
+ return
+ }
+ cv.SetConfiguration(&conf)
+ }
+ go func() {
+ t := time.NewTicker(time.Second)
+ for {
+ updateConfView()
+ <- t.C
+ }
+ }()
+ showRunningView := func(on bool) {
+ cv.SetVisible(on)
+ cv.SetEnabled(on)
+ se.SetVisible(!on)
+ tl.SetVisible(!on)
+ if on {
+ updateConfView()
+ }
+ mw.Invalidate()
+ }
+
pb, _ := walk.NewPushButton(mw)
pb.SetText("Start")
- var runningTunnel *service.Tunnel
pb.Clicked().Attach(func() {
restoreState := true
pbE := pb.Enabled()
@@ -143,6 +177,7 @@ func RunUI() {
if button == walk.LeftButton {
mw.Show()
win.SetForegroundWindow(mw.Handle())
+ updateConfView()
}
})
@@ -153,11 +188,13 @@ func RunUI() {
//TODO: also set tray icon to reflect state
switch state {
case service.TunnelStarting:
+ showRunningView(false)
se.SetEnabled(false)
pb.SetText("Starting...")
pb.SetEnabled(false)
tray.SetToolTip("WireGuard: Activating...")
case service.TunnelStarted:
+ showRunningView(true)
se.SetEnabled(false)
pb.SetText("Stop")
pb.SetEnabled(true)
@@ -167,11 +204,13 @@ func RunUI() {
tray.ShowInfo("WireGuard Activated", fmt.Sprintf("The %s tunnel has been activated.", tunnel.Name))
}
case service.TunnelStopping:
+ showRunningView(false)
se.SetEnabled(false)
pb.SetText("Stopping...")
pb.SetEnabled(false)
tray.SetToolTip("WireGuard: Deactivating...")
case service.TunnelStopped, service.TunnelDeleting:
+ showRunningView(false)
if runningTunnel != nil {
runningTunnel.Delete()
runningTunnel = nil