From 793549f644302f08f5c1b28451a98ffd0eecf0d1 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Sat, 27 Apr 2019 16:39:06 +0200 Subject: ui: fix UI hide/quit logic --- ui/managewindow.go | 3 ++- ui/tunnelspage.go | 2 ++ ui/ui.go | 20 +++++++++++++------- 3 files changed, 17 insertions(+), 8 deletions(-) (limited to 'ui') diff --git a/ui/managewindow.go b/ui/managewindow.go index 85c55844..c4d6dc3c 100644 --- a/ui/managewindow.go +++ b/ui/managewindow.go @@ -46,7 +46,8 @@ func NewManageTunnelsWindow() (*ManageTunnelsWindow, error) { mtw.SetLayout(walk.NewVBoxLayout()) mtw.Closing().Attach(func(canceled *bool, reason walk.CloseReason) { // "Close to tray" instead of exiting application - onQuit() + *canceled = true + mtw.Hide() }) mtw.VisibleChanged().Attach(func() { if mtw.Visible() { diff --git a/ui/tunnelspage.go b/ui/tunnelspage.go index a3ecf0c0..86ab1235 100644 --- a/ui/tunnelspage.go +++ b/ui/tunnelspage.go @@ -321,6 +321,8 @@ func (tp *TunnelsPage) onDelete() { } func (tp *TunnelsPage) onImport() { + tp.Form().Show() // Since the tray calls us sometimes, always make our parent visible. + dlg := walk.FileDialog{ Filter: "Configuration Files (*.zip, *.conf)|*.zip;*.conf|All Files (*.*)|*.*", Title: "Import tunnel(s) from file...", diff --git a/ui/ui.go b/ui/ui.go index d186a905..6ea0a8f6 100644 --- a/ui/ui.go +++ b/ui/ui.go @@ -20,6 +20,8 @@ import "C" var iconProvider *IconProvider +var shouldQuitManagerWhenExiting = false + func RunUI() { runtime.LockOSThread() @@ -37,28 +39,32 @@ func RunUI() { walk.MsgBox(nil, "Unable to initialize icon provider", fmt.Sprint(err), walk.MsgBoxIconError) return } - defer iconProvider.Dispose() mtw, err := NewManageTunnelsWindow() if err != nil { panic(err) } - defer mtw.Dispose() tray, err := NewTray(mtw) if err != nil { panic(err) } - defer tray.Dispose() mtw.Run() + tray.Dispose() + mtw.Dispose() + iconProvider.Dispose() + + if shouldQuitManagerWhenExiting { + _, err := service.IPCClientQuit(true) + if err != nil { + walk.MsgBox(nil, "Error Exiting WireGuard", fmt.Sprintf("Unable to exit service due to: %s. You may want to stop WireGuard from the service manager.", err), walk.MsgBoxIconError) + } + } } func onQuit() { - _, err := service.IPCClientQuit(true) - if err != nil { - walk.MsgBox(nil, "Error Exiting WireGuard", fmt.Sprintf("Unable to exit service due to: %s. You may want to stop WireGuard from the service manager.", err), walk.MsgBoxIconError) - } + shouldQuitManagerWhenExiting = true walk.App().Exit(0) } -- cgit v1.2.3-59-g8ed1b