Files
Iris/src/js/store/index.js

148 lines
4.0 KiB
JavaScript
Raw Normal View History

2016-10-03 15:22:15 +13:00
import { createStore, applyMiddleware, combineReducers } from 'redux';
2019-04-22 13:20:32 +12:00
import * as helpers from '../helpers';
2019-04-22 13:20:32 +12:00
import core from '../services/core/reducer';
import ui from '../services/ui/reducer';
import pusher from '../services/pusher/reducer';
import mopidy from '../services/mopidy/reducer';
import lastfm from '../services/lastfm/reducer';
import spotify from '../services/spotify/reducer';
import snapcast from '../services/snapcast/reducer';
import google from '../services/google/reducer';
import genius from '../services/genius/reducer';
2019-04-22 13:20:32 +12:00
import migration from './migration';
import thunk from 'redux-thunk';
2019-04-22 13:20:32 +12:00
import coreMiddleware from '../services/core/middleware';
import uiMiddleware from '../services/ui/middleware';
import pusherMiddleware from '../services/pusher/middleware';
import mopidyMiddleware from '../services/mopidy/middleware';
import lastfmMiddleware from '../services/lastfm/middleware';
import geniusMiddleware from '../services/genius/middleware';
import spotifyMiddleware from '../services/spotify/middleware';
import googleMiddleware from '../services/google/middleware';
import snapcastMiddleware from '../services/snapcast/middleware';
import localstorageMiddleware from '../services/localstorage/middleware';
2016-10-03 15:22:15 +13:00
let state = {
core: {
outputs: [],
2017-11-10 15:56:01 +13:00
queue: [],
queue_metadata: {},
current_track: null,
albums: {},
artists: {},
playlists: {},
users: {},
tracks: {},
http_streaming_enabled: false,
2018-07-02 21:37:24 +12:00
http_streaming_cachebuster: null,
http_streaming_url: "http://"+window.location.hostname+":8000/mopidy"
},
ui: {
2018-08-24 16:10:41 +12:00
theme: 'dark',
smooth_scrolling_enabled: true,
hotkeys_enabled: true,
2018-06-18 08:38:03 +12:00
allow_reporting: true,
wide_scrollbar_enabled: false,
window_focus: true,
slim_mode: false,
selected_tracks: [],
notifications: {},
processes: {}
},
2016-10-18 08:56:53 +13:00
mopidy: {
connected: false,
2016-10-18 08:56:53 +13:00
host: window.location.hostname,
port: (window.location.port ? window.location.port : (window.location.protocol === 'https:' ? '443' : '80')),
ssl: (window.location.protocol === 'https:' ? true : false),
2017-05-19 11:33:06 +12:00
mute: false,
volume: 0,
progress: 0,
play_state: null,
uri_schemes: [],
library_albums_uri: 'local:directory?type=album',
library_artists_uri: 'local:directory?type=artist'
},
2016-10-27 16:58:11 +13:00
pusher: {
connected: false,
username: helpers.generateGuid(),
client_id: helpers.generateGuid(),
2017-02-19 21:27:43 +13:00
connections: {},
version: {
current: null
2018-03-26 10:36:13 +13:00
},
config: {}
2016-10-27 16:58:11 +13:00
},
2016-11-07 21:21:15 +13:00
lastfm: {
me: null,
authorization_url: 'https://jamesbarnsley.co.nz/iris/auth_lastfm.php'
},
2018-06-27 20:30:04 +12:00
genius: {
me: null,
authorization_url: 'https://jamesbarnsley.co.nz/iris/auth_genius.php'
2018-06-26 21:44:51 +12:00
},
spotify: {
me: null,
autocomplete_results: {},
authorization_url: 'https://jamesbarnsley.co.nz/iris/auth_spotify.php'
},
google: {
enabled: false
},
snapcast: {
streams: {},
groups: {},
clients: {},
server: null,
2018-10-09 21:39:38 +13:00
commands: {}
2016-10-18 08:56:53 +13:00
}
};
2017-11-23 17:43:29 +13:00
// load all our stored values from LocalStorage
state.core = Object.assign({}, state.core, helpers.getStorage('core'));
state.ui = Object.assign({}, state.ui, helpers.getStorage('ui'));
state.mopidy = Object.assign({}, state.mopidy, helpers.getStorage('mopidy'));
state.pusher = Object.assign({}, state.pusher, helpers.getStorage('pusher'));
state.spotify = Object.assign({}, state.spotify, helpers.getStorage('spotify'));
state.lastfm = Object.assign({}, state.lastfm, helpers.getStorage('lastfm'));
state.genius = Object.assign({}, state.genius, helpers.getStorage('genius'));
state.google = Object.assign({}, state.google, helpers.getStorage('google'));
state.snapcast = Object.assign({}, state.snapcast, helpers.getStorage('snapcast'));
// Run any migrations
2019-04-22 13:20:32 +12:00
state = migration(state);
const reducers = combineReducers({
core,
ui,
pusher,
mopidy,
lastfm,
genius,
spotify,
google,
snapcast
});
export default createStore(
reducers,
state,
applyMiddleware(
thunk,
localstorageMiddleware,
coreMiddleware,
uiMiddleware,
mopidyMiddleware,
pusherMiddleware,
spotifyMiddleware,
lastfmMiddleware,
geniusMiddleware,
googleMiddleware,
snapcastMiddleware
)
);