2017-01-19 06:06:32 +00:00
|
|
|
import { assign } from 'lodash'
|
2016-11-26 03:25:35 +00:00
|
|
|
import isMobile from 'ismobilejs'
|
2015-12-13 04:42:28 +00:00
|
|
|
|
2016-11-26 03:25:35 +00:00
|
|
|
import { http } from '../services'
|
|
|
|
import { userStore, preferenceStore, artistStore, songStore, playlistStore, queueStore, settingStore } from '.'
|
2016-06-25 10:15:57 +00:00
|
|
|
|
|
|
|
export const sharedStore = {
|
2017-01-19 04:11:25 +00:00
|
|
|
state: {
|
|
|
|
songs: [],
|
|
|
|
albums: [],
|
|
|
|
artists: [],
|
|
|
|
favorites: [],
|
|
|
|
queued: [],
|
|
|
|
interactions: [],
|
|
|
|
users: [],
|
|
|
|
settings: [],
|
|
|
|
currentUser: null,
|
|
|
|
playlists: [],
|
|
|
|
useLastfm: false,
|
|
|
|
useYouTube: false,
|
|
|
|
useiTunes: false,
|
|
|
|
allowDownload: false,
|
|
|
|
currentVersion: '',
|
|
|
|
latestVersion: '',
|
|
|
|
cdnUrl: '',
|
|
|
|
originalMediaPath: ''
|
|
|
|
},
|
2015-12-13 04:42:28 +00:00
|
|
|
|
2016-11-26 03:25:35 +00:00
|
|
|
init () {
|
2016-06-27 06:11:35 +00:00
|
|
|
return new Promise((resolve, reject) => {
|
2017-01-12 16:50:00 +00:00
|
|
|
http.get('data', ({ data }) => {
|
|
|
|
assign(this.state, data)
|
2016-06-27 06:11:35 +00:00
|
|
|
// Don't allow downloading on mobile devices
|
2016-12-20 15:44:47 +00:00
|
|
|
this.state.allowDownload = this.state.allowDownload && !isMobile.any
|
2015-12-20 12:17:35 +00:00
|
|
|
|
2016-07-30 15:32:17 +00:00
|
|
|
// Always disable YouTube integration on mobile.
|
2016-11-26 03:25:35 +00:00
|
|
|
this.state.useYouTube = this.state.useYouTube && !isMobile.phone
|
2016-07-30 15:32:17 +00:00
|
|
|
|
2016-06-27 06:11:35 +00:00
|
|
|
// If this is a new user, initialize his preferences to be an empty object.
|
|
|
|
if (!this.state.currentUser.preferences) {
|
2016-11-26 03:25:35 +00:00
|
|
|
this.state.currentUser.preferences = {}
|
2016-06-27 06:11:35 +00:00
|
|
|
}
|
2015-12-13 04:42:28 +00:00
|
|
|
|
2016-11-26 03:25:35 +00:00
|
|
|
userStore.init(this.state.users, this.state.currentUser)
|
|
|
|
preferenceStore.init(this.state.preferences)
|
|
|
|
artistStore.init(this.state.artists) // This will init album and song stores as well.
|
|
|
|
songStore.initInteractions(this.state.interactions)
|
|
|
|
playlistStore.init(this.state.playlists)
|
|
|
|
queueStore.init()
|
|
|
|
settingStore.init(this.state.settings)
|
2015-12-22 17:46:54 +00:00
|
|
|
|
2016-08-13 10:43:25 +00:00
|
|
|
// Keep a copy of the media path. We'll need this to properly warn the user later.
|
2016-11-26 03:25:35 +00:00
|
|
|
this.state.originalMediaPath = this.state.settings.media_path
|
2016-08-13 10:43:25 +00:00
|
|
|
|
2016-12-20 15:44:47 +00:00
|
|
|
resolve(this.state)
|
|
|
|
}, error => reject(error))
|
2016-11-26 03:25:35 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|