2022-04-15 14:24:30 +00:00
|
|
|
import isMobile from 'ismobilejs'
|
2022-04-24 08:50:45 +00:00
|
|
|
import { reactive } from 'vue'
|
|
|
|
import { httpService } from '@/services'
|
2022-08-10 14:56:01 +00:00
|
|
|
import { playlistFolderStore, playlistStore, preferenceStore, settingStore, themeStore, userStore } from '@/stores'
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2022-04-24 08:50:45 +00:00
|
|
|
interface CommonStoreState {
|
2022-06-10 10:47:46 +00:00
|
|
|
allow_download: boolean
|
|
|
|
cdn_url: string
|
|
|
|
current_user: User
|
|
|
|
current_version: string
|
|
|
|
latest_version: string
|
2022-04-15 14:24:30 +00:00
|
|
|
playlists: Playlist[]
|
2022-08-10 14:56:01 +00:00
|
|
|
playlist_folders: PlaylistFolder[]
|
2022-04-15 14:24:30 +00:00
|
|
|
settings: Settings
|
2022-06-10 10:47:46 +00:00
|
|
|
use_i_tunes: boolean
|
|
|
|
use_last_fm: boolean
|
2022-07-16 22:42:29 +00:00
|
|
|
use_spotify: boolean
|
2022-04-15 14:24:30 +00:00
|
|
|
users: User[]
|
2022-06-10 10:47:46 +00:00
|
|
|
use_you_tube: boolean,
|
|
|
|
song_count: number,
|
|
|
|
song_length: number
|
2022-04-15 14:24:30 +00:00
|
|
|
}
|
|
|
|
|
2022-04-24 08:50:45 +00:00
|
|
|
export const commonStore = {
|
|
|
|
state: reactive<CommonStoreState>({
|
2022-06-10 10:47:46 +00:00
|
|
|
allow_download: false,
|
|
|
|
cdn_url: '',
|
|
|
|
current_user: undefined as unknown as User,
|
|
|
|
current_version: '',
|
|
|
|
latest_version: '',
|
2022-04-15 14:24:30 +00:00
|
|
|
playlists: [],
|
2022-08-10 14:56:01 +00:00
|
|
|
playlist_folders: [],
|
2022-04-15 14:24:30 +00:00
|
|
|
settings: {} as Settings,
|
2022-06-10 10:47:46 +00:00
|
|
|
use_i_tunes: false,
|
|
|
|
use_last_fm: false,
|
2022-07-16 22:42:29 +00:00
|
|
|
use_spotify: false,
|
2022-04-15 14:24:30 +00:00
|
|
|
users: [],
|
2022-06-10 10:47:46 +00:00
|
|
|
use_you_tube: false,
|
|
|
|
song_count: 0,
|
|
|
|
song_length: 0
|
2022-04-20 15:57:53 +00:00
|
|
|
}),
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2022-04-24 08:50:45 +00:00
|
|
|
async init () {
|
|
|
|
Object.assign(this.state, await httpService.get<CommonStoreState>('data'))
|
2022-04-15 14:24:30 +00:00
|
|
|
|
|
|
|
// Always disable YouTube integration on mobile.
|
2022-06-10 10:47:46 +00:00
|
|
|
this.state.use_you_tube = this.state.use_you_tube && !isMobile.phone
|
2022-04-15 14:24:30 +00:00
|
|
|
|
|
|
|
// If this is a new user, initialize his preferences to be an empty object.
|
2022-06-10 10:47:46 +00:00
|
|
|
this.state.current_user.preferences = this.state.current_user.preferences || {}
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2022-06-10 10:47:46 +00:00
|
|
|
userStore.init(this.state.current_user)
|
|
|
|
preferenceStore.init(this.state.current_user)
|
2022-04-15 14:24:30 +00:00
|
|
|
playlistStore.init(this.state.playlists)
|
2022-08-10 14:56:01 +00:00
|
|
|
playlistFolderStore.init(this.state.playlist_folders)
|
2022-04-15 14:24:30 +00:00
|
|
|
settingStore.init(this.state.settings)
|
|
|
|
themeStore.init()
|
|
|
|
|
|
|
|
return this.state
|
|
|
|
}
|
|
|
|
}
|