From 62803b9f09993880d0693a2934c6da517e23e722 Mon Sep 17 00:00:00 2001 From: Drew Weymouth Date: Tue, 20 Aug 2024 08:00:25 -0700 Subject: [PATCH] save settings when window closing to avoid losing some settings on crash-exits --- backend/app.go | 6 ++++-- ui/mainwindow.go | 8 +++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/backend/app.go b/backend/app.go index 2e89015..53fa84e 100644 --- a/backend/app.go +++ b/backend/app.go @@ -336,16 +336,18 @@ func (a *App) DeleteServerCacheDir(serverID uuid.UUID) error { } func (a *App) Shutdown() { + a.Config.LocalPlayback.Volume = a.LocalPlayer.GetVolume() + a.SavePlayQueueIfEnabled() + a.SaveConfigFile() + if a.ipcServer != nil { a.ipcServer.Shutdown(a.bgrndCtx) } a.MPRISHandler.Shutdown() a.PlaybackManager.DisableCallbacks() a.PlaybackManager.Stop() // will trigger scrobble check - a.Config.LocalPlayback.Volume = a.LocalPlayer.GetVolume() a.cancel() a.LocalPlayer.Destroy() - a.Config.WriteConfigFile(a.configFilePath()) } func (a *App) SavePlayQueueIfEnabled() { diff --git a/ui/mainwindow.go b/ui/mainwindow.go index 40b8d25..bb33ada 100644 --- a/ui/mainwindow.go +++ b/ui/mainwindow.go @@ -140,8 +140,14 @@ func NewMainWindow(fyneApp fyne.App, appName, displayAppName, appVersion string, m.Window.SetContent(fynetooltip.AddWindowToolTipLayer(m.container, m.Window.Canvas())) m.setInitialSize() m.Window.SetCloseIntercept(func() { - app.SavePlayQueueIfEnabled() m.SaveWindowSize() + // save settings in case we crash during shutdown + // TODO: when all shutdowns exit cleanly, remove these lines + // as they are already executed in app.Shutdown() + app.Config.LocalPlayback.Volume = app.LocalPlayer.GetVolume() + app.SavePlayQueueIfEnabled() + app.SaveConfigFile() + if app.Config.Application.CloseToSystemTray && m.HaveSystemTray() { m.Window.Hide() } else {