save and load play queue on exit/startup (partial impl)

This commit is contained in:
Drew Weymouth
2024-01-07 16:25:15 -08:00
parent d2743815bf
commit c4c4a71d5e
4 changed files with 134 additions and 25 deletions
+12
View File
@@ -25,6 +25,7 @@ const (
sessionDir = "session"
sessionLockFile = ".lock"
sessionActivateFile = ".activate"
savedQueueFile = "saved_queue.json"
)
var (
@@ -300,6 +301,9 @@ func (a *App) DeleteServerCacheDir(serverID uuid.UUID) error {
func (a *App) Shutdown() {
a.MPRISHandler.Shutdown()
a.PlaybackManager.DisableCallbacks()
if a.Config.Application.SavePlayQueue {
SavePlayQueue(a.ServerManager.ServerID.String(), a.PlaybackManager, configdir.LocalConfig(a.appName, savedQueueFile))
}
a.PlaybackManager.Stop() // will trigger scrobble check
a.Config.LocalPlayback.Volume = a.LocalPlayer.GetVolume()
a.cancel()
@@ -308,6 +312,14 @@ func (a *App) Shutdown() {
os.RemoveAll(configdir.LocalConfig(a.appName, sessionDir))
}
func (a *App) LoadSavedPlayQueue() error {
queue, err := LoadPlayQueue(configdir.LocalConfig(a.appName, savedQueueFile), a.ServerManager)
if err != nil {
return err
}
return a.PlaybackManager.LoadTracks(queue.Tracks, false, false)
}
func (a *App) SaveConfigFile() {
a.Config.WriteConfigFile(a.configPath())
a.lastWrittenCfg = *a.Config