2016-11-11 16:47:32 +13:00
|
|
|
|
|
|
|
|
|
2016-12-14 08:29:24 +13:00
|
|
|
var uiActions = require('./actions.js')
|
2016-11-11 16:47:32 +13:00
|
|
|
var spotifyActions = require('../spotify/actions.js')
|
|
|
|
|
var helpers = require('../../helpers.js')
|
|
|
|
|
|
|
|
|
|
const UIMiddleware = (function(){
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The actual middleware inteceptor
|
|
|
|
|
**/
|
|
|
|
|
return store => next => action => {
|
|
|
|
|
|
|
|
|
|
switch(action.type){
|
|
|
|
|
|
2016-12-13 11:08:13 +13:00
|
|
|
case 'CREATE_NOTIFICATION':
|
|
|
|
|
|
|
|
|
|
// start a timeout to remove this notification
|
|
|
|
|
var timeout = setTimeout(
|
|
|
|
|
function(){
|
2016-12-14 08:29:24 +13:00
|
|
|
store.dispatch(uiActions.removeNotification(action.notification.id))
|
2016-12-13 11:08:13 +13:00
|
|
|
},
|
|
|
|
|
3000
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
next(action)
|
|
|
|
|
break
|
|
|
|
|
|
2016-12-14 08:29:24 +13:00
|
|
|
case 'PLAYLIST_TRACKS_ADDED':
|
|
|
|
|
|
|
|
|
|
store.dispatch(uiActions.createNotification('Added '+action.tracks_uris.length+' tracks to playlist'))
|
|
|
|
|
|
2016-12-15 12:54:41 +13:00
|
|
|
next(action)
|
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case 'MOPIDY_STATE':
|
|
|
|
|
helpers.setWindowTitle(store.getState().ui.current_track, action.data)
|
|
|
|
|
next(action)
|
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
case 'MOPIDY_CURRENTTLTRACK':
|
|
|
|
|
if( action.data && action.data.track ) helpers.setWindowTitle(action.data.track, store.getState().mopidy.play_state)
|
2016-12-14 08:29:24 +13:00
|
|
|
next(action)
|
|
|
|
|
break
|
|
|
|
|
|
2016-12-20 07:56:42 +13:00
|
|
|
case 'PUSHER_VERSION':
|
|
|
|
|
if( action.data.version.upgrade_available )
|
|
|
|
|
store.dispatch( uiActions.createNotification( 'Version '+action.data.version.latest+' is available. See settings to upgrade.' ) )
|
|
|
|
|
next( action )
|
|
|
|
|
break
|
|
|
|
|
|
2016-11-11 16:47:32 +13:00
|
|
|
// This action is irrelevant to us, pass it on to the next middleware
|
|
|
|
|
default:
|
2016-12-13 11:08:13 +13:00
|
|
|
return next(action)
|
2016-11-11 16:47:32 +13:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
})();
|
|
|
|
|
|
|
|
|
|
export default UIMiddleware
|