aboutsummaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2019-09-24 14:03:24 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2019-09-27 10:44:35 +0200
commit39b26db771668473508c64b95be42aa71108e325 (patch)
tree9ff872f93de0c64a1ddb74200d4d59713f3c0d6b /ui
parentmod: bump versions (diff)
downloadwireguard-windows-39b26db771668473508c64b95be42aa71108e325.tar.xz
wireguard-windows-39b26db771668473508c64b95be42aa71108e325.zip
ui: don't show more than one about box
Reported-by: Kai Haberzettl <khaberz@gmail.com>
Diffstat (limited to 'ui')
-rw-r--r--ui/aboutdialog.go47
1 files changed, 29 insertions, 18 deletions
diff --git a/ui/aboutdialog.go b/ui/aboutdialog.go
index 5a7d6127..ab3b17e7 100644
--- a/ui/aboutdialog.go
+++ b/ui/aboutdialog.go
@@ -18,12 +18,19 @@ import (
)
var easterEggIndex = -1
+var showingAboutDialog *walk.Dialog
func onAbout(owner walk.Form) {
showError(runAboutDialog(owner), owner)
}
func runAboutDialog(owner walk.Form) error {
+ if showingAboutDialog != nil {
+ showingAboutDialog.Show()
+ raise(showingAboutDialog.Handle())
+ return nil
+ }
+
vbl := walk.NewVBoxLayout()
vbl.SetMargins(walk.Margins{80, 20, 80, 20})
vbl.SetSpacing(10)
@@ -31,28 +38,32 @@ func runAboutDialog(owner walk.Form) error {
var disposables walk.Disposables
defer disposables.Treat()
- dlg, err := walk.NewDialogWithFixedSize(owner)
+ var err error
+ showingAboutDialog, err = walk.NewDialogWithFixedSize(owner)
if err != nil {
return err
}
- disposables.Add(dlg)
- dlg.SetTitle("About WireGuard")
- dlg.SetLayout(vbl)
+ defer func() {
+ showingAboutDialog = nil
+ }()
+ disposables.Add(showingAboutDialog)
+ showingAboutDialog.SetTitle("About WireGuard")
+ showingAboutDialog.SetLayout(vbl)
if icon, err := loadLogoIcon(32); err == nil {
- dlg.SetIcon(icon)
+ showingAboutDialog.SetIcon(icon)
}
font, _ := walk.NewFont("Segoe UI", 9, 0)
- dlg.SetFont(font)
+ showingAboutDialog.SetFont(font)
- iv, err := walk.NewImageView(dlg)
+ iv, err := walk.NewImageView(showingAboutDialog)
if err != nil {
return err
}
iv.SetCursor(walk.CursorHand())
iv.MouseUp().Attach(func(x, y int, button walk.MouseButton) {
if button == walk.LeftButton {
- win.ShellExecute(dlg.Handle(), nil, windows.StringToUTF16Ptr("https://www.wireguard.com/"), nil, nil, win.SW_SHOWNORMAL)
+ win.ShellExecute(showingAboutDialog.Handle(), nil, windows.StringToUTF16Ptr("https://www.wireguard.com/"), nil, nil, win.SW_SHOWNORMAL)
} else if easterEggIndex >= 0 && button == walk.RightButton {
if icon, err := loadSystemIcon("moricons", int32(easterEggIndex), 128); err == nil {
iv.SetImage(icon)
@@ -69,7 +80,7 @@ func runAboutDialog(owner walk.Form) error {
iv.SetImage(logo)
}
- wgLbl, err := walk.NewTextLabel(dlg)
+ wgLbl, err := walk.NewTextLabel(showingAboutDialog)
if err != nil {
return err
}
@@ -78,14 +89,14 @@ func runAboutDialog(owner walk.Form) error {
wgLbl.SetTextAlignment(walk.AlignHCenterVNear)
wgLbl.SetText("WireGuard")
- detailsLbl, err := walk.NewTextLabel(dlg)
+ detailsLbl, err := walk.NewTextLabel(showingAboutDialog)
if err != nil {
return err
}
detailsLbl.SetTextAlignment(walk.AlignHCenterVNear)
detailsLbl.SetText(fmt.Sprintf("App version: %s\nGo backend version: %s\nGo version: %s\nOperating system: %s\nArchitecture: %s", version.Number, device.WireGuardGoVersion, strings.TrimPrefix(runtime.Version(), "go"), version.OsName(), runtime.GOARCH))
- copyrightLbl, err := walk.NewTextLabel(dlg)
+ copyrightLbl, err := walk.NewTextLabel(showingAboutDialog)
if err != nil {
return err
}
@@ -94,7 +105,7 @@ func runAboutDialog(owner walk.Form) error {
copyrightLbl.SetTextAlignment(walk.AlignHCenterVNear)
copyrightLbl.SetText("Copyright © 2015-2019 Jason A. Donenfeld. All Rights Reserved.")
- buttonCP, err := walk.NewComposite(dlg)
+ buttonCP, err := walk.NewComposite(showingAboutDialog)
if err != nil {
return err
}
@@ -108,7 +119,7 @@ func runAboutDialog(owner walk.Form) error {
}
closePB.SetAlignment(walk.AlignHCenterVNear)
closePB.SetText("Close")
- closePB.Clicked().Attach(dlg.Accept)
+ closePB.Clicked().Attach(showingAboutDialog.Accept)
donatePB, err := walk.NewPushButton(buttonCP)
if err != nil {
return err
@@ -119,17 +130,17 @@ func runAboutDialog(owner walk.Form) error {
if easterEggIndex == -1 {
easterEggIndex = 0
}
- win.ShellExecute(dlg.Handle(), nil, windows.StringToUTF16Ptr("https://www.wireguard.com/donations/"), nil, nil, win.SW_SHOWNORMAL)
- dlg.Accept()
+ win.ShellExecute(showingAboutDialog.Handle(), nil, windows.StringToUTF16Ptr("https://www.wireguard.com/donations/"), nil, nil, win.SW_SHOWNORMAL)
+ showingAboutDialog.Accept()
})
walk.NewHSpacer(buttonCP)
- dlg.SetDefaultButton(donatePB)
- dlg.SetCancelButton(closePB)
+ showingAboutDialog.SetDefaultButton(donatePB)
+ showingAboutDialog.SetCancelButton(closePB)
disposables.Spare()
- dlg.Run()
+ showingAboutDialog.Run()
return nil
}