nuclear icon indicating copy to clipboard operation
nuclear copied to clipboard

Play queue not persisted.

Open will-ca opened this issue 2 years ago • 10 comments

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.

will-ca avatar Feb 08 '23 12:02 will-ca

I'm interested in working on this.

psoder avatar Feb 28 '23 19:02 psoder

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.

nukeop avatar Feb 28 '23 19:02 nukeop

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?

psoder avatar Mar 01 '23 18:03 psoder

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.

nukeop avatar Mar 01 '23 19:03 nukeop

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?

will-ca avatar Mar 02 '23 00:03 will-ca

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

nukeop avatar Mar 02 '23 00:03 nukeop

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

mud1tx avatar Apr 18 '23 19:04 mud1tx

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.

nukeop avatar Apr 18 '23 23:04 nukeop

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 ?

mud1tx avatar Apr 19 '23 02:04 mud1tx

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

nukeop avatar Apr 19 '23 09:04 nukeop