Skip to content

Commit

Permalink
fix various various playlist bugs on new installations, show electron…
Browse files Browse the repository at this point in the history
… dev tools with env variable
  • Loading branch information
benkaiser committed Jan 4, 2016
1 parent 44e7beb commit 3b43e8d
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 32 deletions.
4 changes: 3 additions & 1 deletion electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ electronApp.on('ready', function() {
mainWindow.loadUrl('http://localhost:' + app.get('port') + '/');

// show the dev tool
// mainWindow.toggleDevTools();
if (process.env.DEVTOOLS) {
mainWindow.toggleDevTools();
}

// Emitted when the window is closed.
mainWindow.on('closed', function() {
Expand Down
4 changes: 3 additions & 1 deletion library_functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,9 @@ var addToPlaylist = function(song_id, playlist_name) {
songs: [{_id: song_id}],
editable: true,
};
app.db.playlists.insert(plist);
app.db.playlists.insert(plist, function(err, newDoc) {
broadcast('addPlaylist', newDoc);
});
} else {
// playlist does exist, inser the song if it isn't already in there
var found = false;
Expand Down
106 changes: 76 additions & 30 deletions static/js/player/socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,22 +55,32 @@ socket.on('sc_update', function(data) {

SCMessenger = updateMask(SCMessenger, 'Added ' + msg + ' (' + data.content.title + ')');

// add the song to the SoundCloud playlist
var sc_plist = player.playlist_collection.getByTitle('SoundCloud').attributes;
sc_plist.songs.push({_id: data.content._id});

// render if we are on the SoundCloud playlist
if (player.playlist.title == 'SoundCloud') {
// update the model data
player.playlist = sc_plist;
player.songs = player.song_collection.getByIds(player.playlist);
player.queue_pool = player.songs.slice(0);
player.genShufflePool();

// resort the model data
player.resortSongs();
redrawSongsChangedModel();
// grab the soundcloud playlist from the collection
var sc_plist = player.playlist_collection.getByTitle('SoundCloud');

// if it existed, do something, otherwise wait for the addPlaylist event
if (sc_plist) {
sc_plist = sc_plist.attributes;

// add the track to the soundcloud playlist
sc_plist.songs.push({_id: data.content._id});

// render if we are on the SoundCloud playlist
if (player.playlist.title == 'SoundCloud') {
// update the model data
player.playlist = sc_plist;
player.songs = player.song_collection.getByIds(player.playlist);
player.queue_pool = player.songs.slice(0);
player.genShufflePool();

// resort the model data
player.resortSongs();
redrawSongsChangedModel();
}
}

// add the track to the library playlist
addToLibraryPlaylist(data.content._id);
} else if (data.type == 'skipped') {
SCMessenger = updateMask(SCMessenger, 'Skipped song ' + data.completed + '. Unable to read from SoundCloud');
} else if (data.type == 'error') {
Expand All @@ -86,21 +96,31 @@ socket.on('yt_update', function(data) {
} else if (data.type == 'added') {
player.song_collection.add(data.content);
YTMessenger = updateMask(YTMessenger, 'Added ' + data.content.title);
var yt_plist = player.playlist_collection.getByTitle('Youtube').attributes;
yt_plist.songs.push({_id: data.content._id});
if (player.playlist.title == 'Youtube') {
// update the model data
player.playlist = yt_plist;
player.songs = player.song_collection.getByIds(player.playlist);
player.queue_pool = player.songs.slice(0);
player.genShufflePool();

// resort the model data
player.resortSongs();

// redraw the songs view
redrawSongsChangedModel();
var yt_plist = player.playlist_collection.getByTitle('Youtube');
if (yt_plist) {
yt_plist = yt_plist.attributes;

// add the track to the youtube playlist
yt_plist.songs.push({_id: data.content._id});

// if the user currently has the youtube playlist focussed, refresh it
if (player.playlist.title == 'Youtube') {
// update the model data
player.playlist = yt_plist;
player.songs = player.song_collection.getByIds(player.playlist);
player.queue_pool = player.songs.slice(0);
player.genShufflePool();

// resort the model data
player.resortSongs();

// redraw the songs view
redrawSongsChangedModel();
}
}

// add the track to the library playlist
addToLibraryPlaylist(data.content._id);
} else if (data.type == 'error') {
YTMessenger = updateMask(YTMessenger, data.content);
}
Expand Down Expand Up @@ -255,10 +275,22 @@ socket.on('similar_songs', function(data) {

// instruct the player to create a view for the mix
player.showMix(data.reqData, songsConverted);

// update the url without navigating
MusicApp.router.navigate('mix/' + encodeURIComponent(data.reqData.title), true);
}
}
});

// add a new playlist
socket.on('addPlaylist', function(data) {
// add the playlist to the collection
player.playlist_collection.add(data);

// redraw the sidebar
MusicApp.router.sidebar();
});

// generic info message reciever
socket.on('message', function(data) {
Messenger().post(data.message);
Expand All @@ -273,5 +305,19 @@ function redrawInfoView() {
}

function addToLibraryPlaylist(id) {
player.playlist_collection.where({_id: 'LIBRARY'})[0].attributes.songs.push({_id: id});
var libraryPlaylist = player.playlist_collection.where({_id: 'LIBRARY'})[0].attributes;
libraryPlaylist.songs.push({_id: id});

// if they are focussed on the Library playlist, refresh it
if (player.playlist.title == 'Library') {
// update the model data
player.playlist = libraryPlaylist;
player.songs = player.song_collection.getByIds(player.playlist);
player.queue_pool = player.songs.slice(0);
player.genShufflePool();

// resort the model data
player.resortSongs();
redrawSongsChangedModel();
}
}

0 comments on commit 3b43e8d

Please sign in to comment.