remember last window size

This commit is contained in:
Drew Weymouth
2023-01-22 16:24:53 -08:00
parent c9bd3b5079
commit 6a931d62f4
3 changed files with 30 additions and 5 deletions
+13 -2
View File
@@ -15,12 +15,23 @@ type ServerConfig struct {
Default bool
}
type AppConfig struct {
WindowWidth int
WindowHeight int
}
type Config struct {
Servers []*ServerConfig
Application AppConfig
Servers []*ServerConfig
}
func DefaultConfig() *Config {
return &Config{}
return &Config{
Application: AppConfig{
WindowWidth: 1000,
WindowHeight: 800,
},
}
}
func ReadConfigFile(filepath string) (*Config, error) {
+15 -1
View File
@@ -7,6 +7,7 @@ import (
"supersonic/ui"
"time"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"github.com/20after4/configdir"
"github.com/zalando/go-keyring"
@@ -29,7 +30,15 @@ func main() {
fyneApp := app.New()
fyneApp.Settings().SetTheme(&ui.MyTheme{})
mainWindow := ui.NewMainWindow(fyneApp, appname, myApp)
w := float32(myApp.Config.Application.WindowWidth)
if w <= 1 {
w = 1000
}
h := float32(myApp.Config.Application.WindowHeight)
if h <= 1 {
h = 800
}
mainWindow := ui.NewMainWindow(fyneApp, appname, myApp, fyne.NewSize(w, h))
// TODO: There is some race condition with running this initial startup
// task immediately before showing and running the window/Fyne main loop where
@@ -55,6 +64,11 @@ func main() {
}()
mainWindow.Show()
mainWindow.Window.SetCloseIntercept(func() {
myApp.Config.Application.WindowHeight = int(mainWindow.Canvas().Size().Height)
myApp.Config.Application.WindowWidth = int(mainWindow.Canvas().Size().Width)
mainWindow.Window.Close()
})
fyneApp.Run()
myApp.Config.WriteConfigFile(configPath())
myApp.Shutdown()
+2 -2
View File
@@ -35,7 +35,7 @@ var (
HomePage = browsing.AlbumsRoute(backend.AlbumSortRecentlyAdded)
)
func NewMainWindow(fyneApp fyne.App, appName string, app *backend.App) MainWindow {
func NewMainWindow(fyneApp fyne.App, appName string, app *backend.App, size fyne.Size) MainWindow {
m := MainWindow{
App: app,
Window: fyneApp.NewWindow(appName),
@@ -48,7 +48,7 @@ func NewMainWindow(fyneApp fyne.App, appName string, app *backend.App) MainWindo
m.BottomPanel.ImageManager = app.ImageManager
m.container = container.NewBorder(nil, m.BottomPanel, nil, nil, m.BrowsingPane)
m.Window.SetContent(m.container)
m.Window.Resize(fyne.NewSize(1000, 800))
m.Window.Resize(size)
app.PlaybackManager.OnSongChange(func(song *subsonic.Child) {
if song == nil {
m.Window.SetTitle(appName)