2016-11-26 03:25:35 +00:00
|
|
|
import { assign } from 'lodash'
|
|
|
|
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 = {
|
2016-06-25 16:05:24 +00:00
|
|
|
state: {
|
|
|
|
songs: [],
|
|
|
|
albums: [],
|
|
|
|
artists: [],
|
|
|
|
favorites: [],
|
|
|
|
queued: [],
|
|
|
|
interactions: [],
|
|
|
|
users: [],
|
|
|
|
settings: [],
|
|
|
|
currentUser: null,
|
|
|
|
playlists: [],
|
|
|
|
useLastfm: false,
|
2016-07-30 15:32:17 +00:00
|
|
|
useYouTube: false,
|
2016-12-11 13:08:30 +00:00
|
|
|
useiTunes: true,
|
2016-06-25 16:05:24 +00:00
|
|
|
allowDownload: false,
|
|
|
|
currentVersion: '',
|
|
|
|
latestVersion: '',
|
|
|
|
cdnUrl: '',
|
2016-11-26 03:25:35 +00:00
|
|
|
originalMediaPath: ''
|
2016-06-25 16:05:24 +00:00
|
|
|
},
|
2015-12-13 04:42:28 +00:00
|
|
|
|
2016-11-26 03:25:35 +00:00
|
|
|
init () {
|
|
|
|
this.reset()
|
2016-02-08 12:21:24 +00:00
|
|
|
|
2016-06-27 06:11:35 +00:00
|
|
|
return new Promise((resolve, reject) => {
|
2016-07-09 04:06:14 +00:00
|
|
|
http.get('data', data => {
|
2016-06-27 06:11:35 +00:00
|
|
|
// Don't allow downloading on mobile devices
|
2016-11-26 03:25:35 +00:00
|
|
|
data.allowDownload = data.allowDownload && !isMobile.any
|
2016-06-04 14:22:28 +00:00
|
|
|
|
2016-11-26 03:25:35 +00:00
|
|
|
assign(this.state, data)
|
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-07-09 04:06:14 +00:00
|
|
|
resolve(data)
|
2016-11-26 03:25:35 +00:00
|
|
|
}, r => reject(r))
|
|
|
|
})
|
2016-06-25 16:05:24 +00:00
|
|
|
},
|
2015-12-22 17:46:54 +00:00
|
|
|
|
2016-11-26 03:25:35 +00:00
|
|
|
reset () {
|
|
|
|
this.state.songs = []
|
|
|
|
this.state.albums = []
|
|
|
|
this.state.artists = []
|
|
|
|
this.state.favorites = []
|
|
|
|
this.state.queued = []
|
|
|
|
this.state.interactions = []
|
|
|
|
this.state.users = []
|
|
|
|
this.state.settings = []
|
|
|
|
this.state.currentUser = null
|
|
|
|
this.state.playlists = []
|
|
|
|
this.state.useLastfm = false
|
2016-12-11 13:08:30 +00:00
|
|
|
this.state.useYouTube = false
|
|
|
|
this.state.useiTunes = true
|
2016-11-26 03:25:35 +00:00
|
|
|
this.state.allowDownload = false
|
|
|
|
this.state.currentVersion = ''
|
|
|
|
this.state.latestVersion = ''
|
|
|
|
this.state.cdnUrl = ''
|
|
|
|
}
|
|
|
|
}
|