perf: save window maximised state #84
This commit is contained in:
parent
d40839506c
commit
2f2fa6bb02
|
@ -112,18 +112,24 @@ func (p *preferencesService) GetAppVersion() (resp types.JSResp) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *preferencesService) SaveWindowSize(width, height int) {
|
func (p *preferencesService) SaveWindowSize(width, height int, maximised bool) {
|
||||||
if width >= consts.MIN_WINDOW_WIDTH && height >= consts.MIN_WINDOW_HEIGHT {
|
if maximised {
|
||||||
|
// do not update window size if maximised state
|
||||||
|
p.UpdatePreferences(map[string]any{
|
||||||
|
"behavior.windowMaximised": true,
|
||||||
|
})
|
||||||
|
} else if width >= consts.MIN_WINDOW_WIDTH && height >= consts.MIN_WINDOW_HEIGHT {
|
||||||
p.UpdatePreferences(map[string]any{
|
p.UpdatePreferences(map[string]any{
|
||||||
"behavior.windowWidth": width,
|
"behavior.windowWidth": width,
|
||||||
"behavior.windowHeight": height,
|
"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()
|
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 {
|
if width <= 0 {
|
||||||
width = consts.DEFAULT_WINDOW_WIDTH
|
width = consts.DEFAULT_WINDOW_WIDTH
|
||||||
}
|
}
|
||||||
|
|
|
@ -111,7 +111,7 @@ func (s *systemService) loopWindowEvent() {
|
||||||
|
|
||||||
if !fullscreen && !minimised {
|
if !fullscreen && !minimised {
|
||||||
// save window size
|
// save window size
|
||||||
Preferences().SaveWindowSize(width, height)
|
Preferences().SaveWindowSize(width, height, maximised)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,7 @@ type PreferencesBehavior struct {
|
||||||
AsideWidth int `json:"asideWidth" yaml:"aside_width"`
|
AsideWidth int `json:"asideWidth" yaml:"aside_width"`
|
||||||
WindowWidth int `json:"windowWidth" yaml:"window_width"`
|
WindowWidth int `json:"windowWidth" yaml:"window_width"`
|
||||||
WindowHeight int `json:"windowHeight" yaml:"window_height"`
|
WindowHeight int `json:"windowHeight" yaml:"window_height"`
|
||||||
|
WindowMaximised bool `json:"windowMaximised" yaml:"window_maximised"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type PreferencesGeneral struct {
|
type PreferencesGeneral struct {
|
||||||
|
|
7
main.go
7
main.go
|
@ -33,7 +33,11 @@ func main() {
|
||||||
cliSvc := services.Cli()
|
cliSvc := services.Cli()
|
||||||
prefSvc := services.Preferences()
|
prefSvc := services.Preferences()
|
||||||
prefSvc.SetAppVersion(version)
|
prefSvc.SetAppVersion(version)
|
||||||
windowWidth, windowHeight := prefSvc.GetWindowSize()
|
windowWidth, windowHeight, maximised := prefSvc.GetWindowSize()
|
||||||
|
windowStartState := options.Normal
|
||||||
|
if maximised {
|
||||||
|
windowStartState = options.Maximised
|
||||||
|
}
|
||||||
|
|
||||||
// menu
|
// menu
|
||||||
appMenu := menu.NewMenu()
|
appMenu := menu.NewMenu()
|
||||||
|
@ -50,6 +54,7 @@ func main() {
|
||||||
Height: windowHeight,
|
Height: windowHeight,
|
||||||
MinWidth: consts.MIN_WINDOW_WIDTH,
|
MinWidth: consts.MIN_WINDOW_WIDTH,
|
||||||
MinHeight: consts.MIN_WINDOW_HEIGHT,
|
MinHeight: consts.MIN_WINDOW_HEIGHT,
|
||||||
|
WindowStartState: windowStartState,
|
||||||
Frameless: runtime.GOOS != "darwin",
|
Frameless: runtime.GOOS != "darwin",
|
||||||
Menu: appMenu,
|
Menu: appMenu,
|
||||||
EnableDefaultContextMenu: true,
|
EnableDefaultContextMenu: true,
|
||||||
|
|
Loading…
Reference in New Issue