From 2f2fa6bb02c96daa286520542cce59a9ce5c6134 Mon Sep 17 00:00:00 2001 From: Lykin <137850705+tiny-craft@users.noreply.github.com> Date: Fri, 24 Nov 2023 11:49:59 +0800 Subject: [PATCH] perf: save window maximised state #84 --- backend/services/preferences_service.go | 18 ++++++++++++------ backend/services/system_service.go | 2 +- backend/types/preferences.go | 7 ++++--- main.go | 7 ++++++- 4 files changed, 23 insertions(+), 11 deletions(-) diff --git a/backend/services/preferences_service.go b/backend/services/preferences_service.go index 0f5e268..1f5b1b0 100644 --- a/backend/services/preferences_service.go +++ b/backend/services/preferences_service.go @@ -112,18 +112,24 @@ func (p *preferencesService) GetAppVersion() (resp types.JSResp) { return } -func (p *preferencesService) SaveWindowSize(width, height int) { - if width >= consts.MIN_WINDOW_WIDTH && height >= consts.MIN_WINDOW_HEIGHT { +func (p *preferencesService) SaveWindowSize(width, height int, maximised bool) { + if maximised { + // do not update window size if maximised state p.UpdatePreferences(map[string]any{ - "behavior.windowWidth": width, - "behavior.windowHeight": height, + "behavior.windowMaximised": true, + }) + } else if width >= consts.MIN_WINDOW_WIDTH && height >= consts.MIN_WINDOW_HEIGHT { + p.UpdatePreferences(map[string]any{ + "behavior.windowWidth": width, + "behavior.windowHeight": height, + "behavior.windowMaximised": false, }) } } -func (p *preferencesService) GetWindowSize() (width, height int) { +func (p *preferencesService) GetWindowSize() (width, height int, maximised bool) { data := p.pref.GetPreferences() - width, height = data.Behavior.WindowWidth, data.Behavior.WindowHeight + width, height, maximised = data.Behavior.WindowWidth, data.Behavior.WindowHeight, data.Behavior.WindowMaximised if width <= 0 { width = consts.DEFAULT_WINDOW_WIDTH } diff --git a/backend/services/system_service.go b/backend/services/system_service.go index 679c3f1..d4b2e5e 100644 --- a/backend/services/system_service.go +++ b/backend/services/system_service.go @@ -111,7 +111,7 @@ func (s *systemService) loopWindowEvent() { if !fullscreen && !minimised { // save window size - Preferences().SaveWindowSize(width, height) + Preferences().SaveWindowSize(width, height, maximised) } } } diff --git a/backend/types/preferences.go b/backend/types/preferences.go index 79ebd81..68f4fd9 100644 --- a/backend/types/preferences.go +++ b/backend/types/preferences.go @@ -29,9 +29,10 @@ func NewPreferences() Preferences { } type PreferencesBehavior struct { - AsideWidth int `json:"asideWidth" yaml:"aside_width"` - WindowWidth int `json:"windowWidth" yaml:"window_width"` - WindowHeight int `json:"windowHeight" yaml:"window_height"` + AsideWidth int `json:"asideWidth" yaml:"aside_width"` + WindowWidth int `json:"windowWidth" yaml:"window_width"` + WindowHeight int `json:"windowHeight" yaml:"window_height"` + WindowMaximised bool `json:"windowMaximised" yaml:"window_maximised"` } type PreferencesGeneral struct { diff --git a/main.go b/main.go index 59b0905..34cab2c 100644 --- a/main.go +++ b/main.go @@ -33,7 +33,11 @@ func main() { cliSvc := services.Cli() prefSvc := services.Preferences() prefSvc.SetAppVersion(version) - windowWidth, windowHeight := prefSvc.GetWindowSize() + windowWidth, windowHeight, maximised := prefSvc.GetWindowSize() + windowStartState := options.Normal + if maximised { + windowStartState = options.Maximised + } // menu appMenu := menu.NewMenu() @@ -50,6 +54,7 @@ func main() { Height: windowHeight, MinWidth: consts.MIN_WINDOW_WIDTH, MinHeight: consts.MIN_WINDOW_HEIGHT, + WindowStartState: windowStartState, Frameless: runtime.GOOS != "darwin", Menu: appMenu, EnableDefaultContextMenu: true,