fix: preference saving might fail

This commit is contained in:
tiny-craft 2023-10-08 23:37:07 +08:00
parent b3c494f15e
commit ab2056ba3e
2 changed files with 8 additions and 12 deletions

View File

@ -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
}

16
main.go
View File

@ -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{}{