nukeop / nuclear

Streaming music player that finds free music for you
https://nuclearplayer.com
GNU Affero General Public License v3.0
12.13k stars 1.06k forks source link

Play queue not persisted. #1398

Open will-ca opened 1 year ago

will-ca commented 1 year ago

If you close and re-open Nuclear, your play queue is gone, and you lose your place.

Not maintaining that state is annoying for E.G. recovering from crashes, working around bugs by restarting, etc. Most music players have an option to save and restore the play queue on exit and re-launch.

psoder commented 1 year ago

I'm interested in working on this.

nukeop commented 1 year ago

Ok, I assigned you. Before committing time and effort, please share a general outline of your approach to this. I suggest this should be an option available in the settings, and persisted somewhere in the config folder, perhaps as a separate json, but no necessarily.

psoder commented 1 year ago

So My plan is more or less to

Load the queue

I don't really know if there's any setup function which I could hook into.

Save the queue

I'm thinking that the easiest way is to save the entier queue to the config file. However, I don't really know where to do this. I'm guessing the best place is in the queue actions file?

When a song ends, remove it from the config

I also don't know if there's a neat way of removing the song that was just played, but I'm sure ill find a way to do it. It can't be that difficult, right?

nukeop commented 1 year ago

Loading

If you search by store.get, you can see a bunch of instances where elements of the config are loaded. packages/core/src/persistence/store.js contains the helper functions for managing the store. You can either use this, or better yet, use the electron-store library to keep the saved queue in a separate file (so if it's big it doesn't slow down other functions of the player). Then, at startup, for example when the queue container is loaded for the first time, you can load the tracks.

Saving

Similarly, store.set lets you save the config. Look for the buildElectronStoreState function to see how it can be mocked and tested.

Syncing the queue

packages/app/app/store/enhancers/syncStorage.js contains code that subscribes to the redux store and syncs settings with the config file. You can use a similar mechanism. While some of those files are still javascript we want all new code to be written in Typescript.

Thanks for discussing this, it's important that we're on the same page so that there's no wasted effort on either side.

will-ca commented 1 year ago

When a song ends, remove it from the config

Does this behaviour reflect how the queue is actually stored in the app and exposed in the UI?

nukeop commented 1 year ago

The queue is stored in redux. You can listen to the changes to reflect them in the persisted state.

mud1tx commented 1 year ago

@nukeop what about storing queue in localStorage of the browser?

nukeop commented 1 year ago

Yeah that could work as well. I prefer to keep everything in one place, but if anyone wants to implement it differently that's fine.

mud1tx commented 1 year ago

Yeah that could work as well. I prefer to keep everything in one place, but if anyone wants to implement it differently that's fine.

Can I give this a try @nukeop ?

nukeop commented 1 year ago

Not sure if the previous contributor is still working on it. You can give it a shot.