move saving play queue to window close intercept instead of app exit in case we crash during exit tasks

This commit is contained in:
Drew Weymouth
2024-08-19 08:46:44 -07:00
parent cf01553974
commit 6075b5c82e
2 changed files with 14 additions and 9 deletions
+13 -9
View File
@@ -341,15 +341,6 @@ func (a *App) Shutdown() {
}
a.MPRISHandler.Shutdown()
a.PlaybackManager.DisableCallbacks()
if a.Config.Application.SavePlayQueue {
var queueServer mediaprovider.CanSavePlayQueue = nil
if a.Config.Application.SaveQueueToServer {
if qs, ok := a.ServerManager.Server.(mediaprovider.CanSavePlayQueue); ok {
queueServer = qs
}
}
SavePlayQueue(a.ServerManager.ServerID.String(), a.PlaybackManager, path.Join(a.configDir, savedQueueFile), queueServer)
}
a.PlaybackManager.Stop() // will trigger scrobble check
a.Config.LocalPlayback.Volume = a.LocalPlayer.GetVolume()
a.cancel()
@@ -357,6 +348,19 @@ func (a *App) Shutdown() {
a.Config.WriteConfigFile(a.configFilePath())
}
func (a *App) SavePlayQueueIfEnabled() {
if !a.Config.Application.SavePlayQueue {
return
}
var queueServer mediaprovider.CanSavePlayQueue = nil
if a.Config.Application.SaveQueueToServer {
if qs, ok := a.ServerManager.Server.(mediaprovider.CanSavePlayQueue); ok {
queueServer = qs
}
}
SavePlayQueue(a.ServerManager.ServerID.String(), a.PlaybackManager, path.Join(a.configDir, savedQueueFile), queueServer)
}
func (a *App) LoadSavedPlayQueue() error {
queueFilePath := path.Join(a.configDir, savedQueueFile)
queue, err := LoadPlayQueue(queueFilePath, a.ServerManager, a.Config.Application.SaveQueueToServer)
+1
View File
@@ -140,6 +140,7 @@ 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()
if app.Config.Application.CloseToSystemTray && m.HaveSystemTray() {
m.Window.Hide()