diff options
author | Alexander Neumann <an2048@gmail.com> | 2019-07-25 15:12:04 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2019-07-29 09:45:07 +0200 |
commit | 0dce279a896c604054f835ac921faa20af26b610 (patch) | |
tree | b267dbf46cd412aa6f13b7d87ca7a586aed08d84 /ui/ui.go | |
parent | ui: use now exposed ItemCountChanged event (diff) | |
download | wireguard-windows-0dce279a896c604054f835ac921faa20af26b610.tar.xz wireguard-windows-0dce279a896c604054f835ac921faa20af26b610.zip |
ui: improve error handling
Signed-off-by: Alexander Neumann <an2048@gmail.com>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to '')
-rw-r--r-- | ui/ui.go | 22 |
1 files changed, 20 insertions, 2 deletions
@@ -26,7 +26,7 @@ func RunUI() { runtime.LockOSThread() defer func() { if err := recover(); err != nil { - walk.MsgBox(nil, "Panic", fmt.Sprint(err, "\n\n", string(debug.Stack())), walk.MsgBoxIconError) + showErrorCustom(nil, "Panic", fmt.Sprint(err, "\n\n", string(debug.Stack()))) panic(err) } }() @@ -95,7 +95,7 @@ func RunUI() { if shouldQuitManagerWhenExiting { _, err := manager.IPCClientQuit(true) if err != nil { - walk.MsgBox(nil, "Error Exiting WireGuard", fmt.Sprintf("Unable to exit service due to: %v. You may want to stop WireGuard from the service manager.", err), walk.MsgBoxIconError) + showErrorCustom(nil, "Error Exiting WireGuard", fmt.Sprintf("Unable to exit service due to: %v. You may want to stop WireGuard from the service manager.", err)) } } } @@ -104,3 +104,21 @@ func onQuit() { shouldQuitManagerWhenExiting = true walk.App().Exit(0) } + +func showError(err error, owner walk.Form) bool { + if err == nil { + return false + } + + showErrorCustom(owner, "Error", err.Error()) + + return true +} + +func showErrorCustom(owner walk.Form, title, message string) { + walk.MsgBox(owner, title, message, walk.MsgBoxIconError) +} + +func showWarningCustom(owner walk.Form, title, message string) { + walk.MsgBox(owner, title, message, walk.MsgBoxIconWarning) +} |