From e08e92b17d09449a1b4f473970eb36f091cc8fd2 Mon Sep 17 00:00:00 2001 From: Jacalz Date: Mon, 15 Jun 2020 15:38:32 +0200 Subject: [PATCH] Set main window as master and use SetOnClosed() instead of defer This should hopefully be a small optimization by running the function on close instead of defering it and keeping it in the call stack. --- internal/gui/init.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/internal/gui/init.go b/internal/gui/init.go index ebb5e92..6ee58bd 100644 --- a/internal/gui/init.go +++ b/internal/gui/init.go @@ -49,6 +49,7 @@ func Init() { // Create the window for our user interface. w := a.NewWindow("Sparta") + w.SetMaster() // Create the user struct type for later use. u := newUser() @@ -65,14 +66,14 @@ func Init() { t := &widget.TabContainer{} t.Append(u.loginTabContainer(a, w, t)) - // Defer creation and storage of a new password hash with random salt. - defer func() { + // Create and store of a new password hash with random salt on window close. + w.SetOnClosed(func() { if key, err := crypto.SaveNewPasswordHash(u.password, u.username, a); err != nil { fyne.LogError("Error on generating password hash", err) } else { u.data.Write(&key, u.username) } - }() + }) // Set the window to a good size, add the content and lastly run the application. w.SetContent(t)