Storing next track and pre-fetching artwork for snappier UI

This commit is contained in:
James Barnsley
2018-04-12 15:55:39 +12:00
parent 4736f85ff2
commit cd4451f69c
13 changed files with 220 additions and 68 deletions

View File

@ -316,7 +316,7 @@ const CoreMiddleware = (function(){
case 'CURRENT_TRACK_LOADED':
store.dispatch({
type: 'TRACKS_LOADED',
tracks: [action.current_track]
tracks: [action.track]
});
next(action);

View File

@ -13,8 +13,13 @@ export default function reducer(core = {}, action){
case 'CURRENT_TRACK_LOADED':
return Object.assign({}, core, {
current_track: action.current_track,
current_track_uri: action.current_track_uri
current_track: action.track,
current_track_uri: action.uri
});
case 'NEXT_TRACK_LOADED':
return Object.assign({}, core, {
next_track_uri: action.uri
});
case 'QUEUE_LOADED':

View File

@ -171,14 +171,6 @@ export function getCurrentTrack(){
}
}
export function clearCurrentTrack(){
return {
type: 'CURRENT_TRACK_LOADED',
current_track: null,
current_track_uri: null
}
}
export function currentTrackLoaded(tl_track){
return {
type: 'MOPIDY_CURRENT_TRACK_LOADED',
@ -186,6 +178,20 @@ export function currentTrackLoaded(tl_track){
}
}
export function getNextTrack(){
return {
type: 'MOPIDY_GET_NEXT_TRACK'
}
}
export function clearCurrentTrack(){
return {
type: 'CURRENT_TRACK_LOADED',
track: null,
uri: null
}
}
export function getQueue(){
return {
type: 'MOPIDY_GET_QUEUE'

View File

@ -72,7 +72,8 @@ const MopidyMiddleware = (function(){
break;
case 'event:tracklistChanged':
store.dispatch(mopidyActions.getQueue())
store.dispatch(mopidyActions.getQueue());
store.dispatch(mopidyActions.getNextTrack());
break;
case 'event:playbackStateChanged':
@ -97,6 +98,7 @@ const MopidyMiddleware = (function(){
case 'event:trackPlaybackStarted':
store.dispatch(mopidyActions.currentTrackLoaded(data.tl_track));
store.dispatch(mopidyActions.getNextTrack());
break;
case 'event:volumeChanged':
@ -2016,23 +2018,60 @@ const MopidyMiddleware = (function(){
case 'MOPIDY_CURRENT_TRACK_LOADED':
var track = helpers.formatTracks(action.tl_track);
// We've got Spotify running, and it's a spotify track - go straight to the source!
if (store.getState().spotify.enabled && helpers.uriSource(track.uri) == 'spotify'){
store.dispatch(spotifyActions.getTrack(track.uri))
// We don't have the track already in our index
if (store.getState().core.tracks[track.uri] === undefined || store.getState().core.tracks[track.uri].images === undefined){
// Some other source, rely on Mopidy backends to do their work
} else {
store.dispatch(mopidyActions.getImages('tracks',[track.uri]))
// We've got Spotify running, and it's a spotify track - go straight to the source!
if (store.getState().spotify.enabled && helpers.uriSource(track.uri) == 'spotify'){
store.dispatch(spotifyActions.getTrack(track.uri));
// Some other source, rely on Mopidy backends to do their work
} else {
store.dispatch(mopidyActions.getImages('tracks',[track.uri]));
}
}
// Set our window title to the track title
helpers.setWindowTitle(track, store.getState().mopidy.play_state);
store.dispatch({
type: 'CURRENT_TRACK_LOADED',
current_track: track
track: track
});
break;
case 'MOPIDY_GET_NEXT_TRACK':
request(socket, store, 'tracklist.getNextTlid')
.then(
response => {
if (response && response >= 0){
var track = helpers.applyFilter('tlid', response, store.getState().core.queue, true);
if (track){
store.dispatch({
type: 'NEXT_TRACK_LOADED',
uri: track.uri
});
console.log(track.name);
// We don't have the track already in our index
if (store.getState().core.tracks[track.uri] === undefined || store.getState().core.tracks[track.uri].images === undefined){
// We've got Spotify running, and it's a spotify track - go straight to the source!
if (store.getState().spotify.enabled && helpers.uriSource(track.uri) == 'spotify'){
store.dispatch(spotifyActions.getTrack(track.uri));
// Some other source, rely on Mopidy backends to do their work
} else {
store.dispatch(mopidyActions.getImages('tracks',[track.uri]));
}
}
}
}
}
);
break;
case 'MOPIDY_GET_TRACK':
request(socket, store, 'library.lookup', action.data )
.then(