From 51d3dec979fc276073002b7d159567e714b3f250 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Tue, 14 May 2019 14:02:33 +0200 Subject: ui: centralize state labels Signed-off-by: Jason A. Donenfeld --- ui/confview.go | 27 +++------------------------ ui/iconprovider.go | 22 ++++++++++++++++++++++ ui/tray.go | 11 +++-------- 3 files changed, 28 insertions(+), 32 deletions(-) diff --git a/ui/confview.go b/ui/confview.go index 11226cc4..869ba229 100644 --- a/ui/confview.go +++ b/ui/confview.go @@ -108,22 +108,7 @@ func (lsl *labelStatusLine) update(state service.TunnelState) { } lsl.statusImage.SetImage(img) s, e := lsl.statusLabel.TextSelection() - switch state { - case service.TunnelStarted: - lsl.statusLabel.SetText("Active") - - case service.TunnelStarting: - lsl.statusLabel.SetText("Activating") - - case service.TunnelStopped: - lsl.statusLabel.SetText("Inactive") - - case service.TunnelStopping: - lsl.statusLabel.SetText("Deactivating") - - case service.TunnelUnknown: - lsl.statusLabel.SetText("Unknown state") - } + lsl.statusLabel.SetText(textForState(state, false)) lsl.statusLabel.SetTextSelection(s, e) } @@ -208,16 +193,10 @@ func (tal *toggleActiveLine) update(state service.TunnelState) { switch state { case service.TunnelStarted: text = "Deactivate" - - case service.TunnelStarting: - text = "Activating..." - case service.TunnelStopped: text = "Activate" - - case service.TunnelStopping: - text = "Deactivating..." - + case service.TunnelStarting, service.TunnelStopping: + text = textForState(state, true) default: text = "" } diff --git a/ui/iconprovider.go b/ui/iconprovider.go index 3b3fd13d..52150a46 100644 --- a/ui/iconprovider.go +++ b/ui/iconprovider.go @@ -101,6 +101,28 @@ func iconForState(state service.TunnelState, size int) (icon *walk.Icon, err err return } +func textForState(state service.TunnelState, withEllipsis bool) (text string) { + switch state { + case service.TunnelStarted: + text = "Active" + case service.TunnelStarting: + text = "Activating" + case service.TunnelStopped: + text = "Inactive" + case service.TunnelStopping: + text = "Deactivating" + case service.TunnelUnknown: + text = "Unknown state" + } + if withEllipsis { + switch state { + case service.TunnelStarting, service.TunnelStopping: + text += "..." + } + } + return +} + var cachedSystemIconsForWidthAndDllIdx = make(map[widthAndDllIdx]*walk.Icon) func loadSystemIcon(dll string, index int32, size int) (icon *walk.Icon, err error) { diff --git a/ui/tray.go b/ui/tray.go index 749748ea..7b5e55ca 100644 --- a/ui/tray.go +++ b/ui/tray.go @@ -234,28 +234,23 @@ func (tray *Tray) updateGlobalState(globalState service.TunnelState) { } } + tray.SetToolTip(fmt.Sprintf("WireGuard: %s", textForState(globalState, true))) + statusAction.SetText(fmt.Sprintf("Status: %s", textForState(globalState, false))) + switch globalState { case service.TunnelStarting: - statusAction.SetText("Status: Activating") setTunnelActionsEnabled(false) - tray.SetToolTip("WireGuard: Activating...") case service.TunnelStarted: activeCIDRsAction.SetVisible(true) - statusAction.SetText("Status: Active") setTunnelActionsEnabled(true) - tray.SetToolTip("WireGuard: Activated") case service.TunnelStopping: - statusAction.SetText("Status: Deactivating") setTunnelActionsEnabled(false) - tray.SetToolTip("WireGuard: Deactivating...") case service.TunnelStopped: activeCIDRsAction.SetVisible(false) - statusAction.SetText("Status: Inactive") setTunnelActionsEnabled(true) - tray.SetToolTip("WireGuard: Deactivated") } } -- cgit v1.2.3-59-g8ed1b