From ab2056ba3ed7013e3d021eb2da2cc42595c69360 Mon Sep 17 00:00:00 2001 From: tiny-craft <137850705+tiny-craft@users.noreply.github.com> Date: Sun, 8 Oct 2023 23:37:07 +0800 Subject: [PATCH] fix: preference saving might fail --- backend/storage/preferences.go | 4 ++++ main.go | 16 ++++------------ 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/backend/storage/preferences.go b/backend/storage/preferences.go index 3435db0..a19f2b4 100644 --- a/backend/storage/preferences.go +++ b/backend/storage/preferences.go @@ -7,6 +7,7 @@ import ( "reflect" "strings" "sync" + "tinyrdm/backend/consts" "tinyrdm/backend/types" ) @@ -45,6 +46,9 @@ func (p *PreferencesStorage) GetPreferences() (ret types.Preferences) { defer p.mutex.Unlock() ret = p.getPreferences() + ret.Behavior.AsideWidth = max(ret.Behavior.AsideWidth, consts.DEFAULT_ASIDE_WIDTH) + ret.Behavior.WindowWidth = max(ret.Behavior.WindowWidth, consts.DEFAULT_WINDOW_WIDTH) + ret.Behavior.WindowHeight = max(ret.Behavior.WindowHeight, consts.DEFAULT_WINDOW_HEIGHT) return } diff --git a/main.go b/main.go index 5cc4ba4..0991cd0 100644 --- a/main.go +++ b/main.go @@ -57,23 +57,15 @@ func main() { app.startup(ctx) connSvc.Start(ctx) }, - //OnBeforeClose: func(ctx context.Context) (prevent bool) { - // // save current window size - // width, height := runtime2.WindowGetSize(ctx) - // if width > 0 && height > 0 { - // if w, h := prefSvc.GetWindowSize(); w != width || h != height { - // prefSvc.SaveWindowSize(width, height) - // } - // } - // return false - //}, - OnShutdown: func(ctx context.Context) { + OnBeforeClose: func(ctx context.Context) (prevent bool) { // save current window size width, height := runtime2.WindowGetSize(ctx) if width > 0 && height > 0 { prefSvc.SaveWindowSize(width, height) } - + return false + }, + OnShutdown: func(ctx context.Context) { connSvc.Stop(ctx) }, Bind: []interface{}{