perf: save window maximised state #84

This commit is contained in:
Lykin 2023-11-24 11:49:59 +08:00
parent d40839506c
commit 2f2fa6bb02
4 changed files with 23 additions and 11 deletions

View File

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

View File

@ -111,7 +111,7 @@ func (s *systemService) loopWindowEvent() {
if !fullscreen && !minimised {
// save window size
Preferences().SaveWindowSize(width, height)
Preferences().SaveWindowSize(width, height, maximised)
}
}
}

View File

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

View File

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