Closed jllodra closed 8 years ago
Do you have a specified format in mind for the saved playlist?
Hi @smithmf,
thanks for the interest.
The format can be the same format used in the playlist
array in the state.js
module.
The following technique is already being used to save the current playlist to localStorage when the application quits (this way the last playlist is always restored when the app opens again):
window.state=state;
window.settings=settings;
state.playlist = settings.get('_lastPlaylist'); // playlist restored
win.on("close", function() { // when the application quits, the playlist is saved to localStorage
player.quit();
settings.set('_lastPlaylist', state.playlist);
this.close(true);
});
If you open the console (ctrl+0) you can examine the state
variable (console.log(state)
), I attached it to the window
object for convenience. The settings
module will serialise the playlist and save it as a string to the _lastPlaylist
localStorage key when the application is closed.
So...
When a Save playlist
is triggered, the process should be quite similar: Show a file picker window, serialise the state.playlist
array and write it to a file using the fs
module.
The Load playlist
is mostly the inverse procedure.
Please let me know if you need more clarification or have better ideas.
This functionality has been implemented in Pull Request #23.
Of note, I currently serialize the full state.playlist
object to the file that is saved. However, we really only need the state.playlist[0].path
property of any element in the playlist. This is because when loading a playlist, I rely on the addSongsToPlaylist
method that takes an array of paths. I am leaving the saved playlist as is, but saving just the path to the song in the playlist might be desirable.
Also, I didn't implement this because it is outside of this issue, but it might be appropriate to add a 'Load Playlist' button on the player window, next to the 'Add File(s)' button. Mainly because you can only currently load a playlist from the contextual menu. If no songs are currently loaded, then you cannot load a playlist. I would guess that the more comfortable UX is to allow a user to load a playlist when no songs are currently in the player.
When right click is pressed on the playlist, a popup menu appears.
It could be great if someone could add 2 options: Load playlist and Save playlist.
This could be programmed in the
playlist.js
file (the popup menu is at the end) and it should be pretty straightforward with a little knowledge of Angular 1 and nwjs...