From 7aba27e5f960db78067bc6a0c0ad25ce7d874dd2 Mon Sep 17 00:00:00 2001 From: tiny-craft <137850705+tiny-craft@users.noreply.github.com> Date: Thu, 28 Sep 2023 21:45:44 +0800 Subject: [PATCH] perf: save window size before close #34 --- backend/consts/default_config.go | 6 ++++++ backend/services/preferences_service.go | 23 +++++++++++++++++++++++ backend/storage/preferences.go | 9 +++++++-- frontend/src/AppContent.vue | 4 ++-- frontend/src/stores/preferences.js | 15 ++++++++++++--- main.go | 17 +++++++++++++---- 6 files changed, 63 insertions(+), 11 deletions(-) create mode 100644 backend/consts/default_config.go diff --git a/backend/consts/default_config.go b/backend/consts/default_config.go new file mode 100644 index 0000000..58f168b --- /dev/null +++ b/backend/consts/default_config.go @@ -0,0 +1,6 @@ +package consts + +const DEFAULT_FONT_SIZE = 14 +const DEFAULT_ASIDE_WIDTH = 300 +const DEFAULT_WINDOW_WIDTH = 1024 +const DEFAULT_WINDOW_HEIGHT = 768 diff --git a/backend/services/preferences_service.go b/backend/services/preferences_service.go index ef58fec..4c92cbf 100644 --- a/backend/services/preferences_service.go +++ b/backend/services/preferences_service.go @@ -7,6 +7,7 @@ import ( "sort" "strings" "sync" + "tinyrdm/backend/consts" storage2 "tinyrdm/backend/storage" "tinyrdm/backend/types" "tinyrdm/backend/utils/coll" @@ -101,6 +102,28 @@ func (p *preferencesService) GetAppVersion() (resp types.JSResp) { return } +func (p *preferencesService) SaveWindowSize(width, height int) { + p.SetPreferences(map[string]any{ + "behavior": map[string]any{ + "window_width": width, + "window_height": height, + }, + }) +} + +func (p *preferencesService) GetWindowSize() (width, height int) { + data := p.pref.GetPreferences() + w, h := data["behavior.window_width"], data["behavior.window_height"] + var ok bool + if width, ok = w.(int); !ok { + return consts.DEFAULT_WINDOW_WIDTH, consts.DEFAULT_WINDOW_HEIGHT + } + if height, ok = h.(int); !ok { + return consts.DEFAULT_WINDOW_WIDTH, consts.DEFAULT_WINDOW_HEIGHT + } + return +} + type latestRelease struct { Name string `json:"name"` TagName string `json:"tag_name"` diff --git a/backend/storage/preferences.go b/backend/storage/preferences.go index 6d678b8..1590d44 100644 --- a/backend/storage/preferences.go +++ b/backend/storage/preferences.go @@ -5,6 +5,7 @@ import ( "gopkg.in/yaml.v3" "strings" "sync" + "tinyrdm/backend/consts" ) type PreferencesStorage struct { @@ -20,15 +21,19 @@ func NewPreferences() *PreferencesStorage { func (p *PreferencesStorage) DefaultPreferences() map[string]any { return map[string]any{ + "behavior": map[string]any{ + "aside_width": consts.DEFAULT_ASIDE_WIDTH, + "window_width": consts.DEFAULT_WINDOW_WIDTH, + "window_height": consts.DEFAULT_WINDOW_HEIGHT, + }, "general": map[string]any{ "language": "auto", "font": "", - "font_size": 14, + "font_size": consts.DEFAULT_FONT_SIZE, "use_sys_proxy": false, "use_sys_proxy_http": false, "check_update": true, "skip_version": "", - "aside_width": 300, }, "editor": map[string]any{ "font": "", diff --git a/frontend/src/AppContent.vue b/frontend/src/AppContent.vue index 020ebe2..70ffa3f 100644 --- a/frontend/src/AppContent.vue +++ b/frontend/src/AppContent.vue @@ -59,7 +59,7 @@ const startResize = () => { } const asideWidthVal = computed(() => { - return prefStore.general.asideWidth + 'px' + return prefStore.behavior.asideWidth + 'px' }) const dragging = computed(() => { @@ -115,7 +115,7 @@ const border = computed(() => {