2022-04-15 14:24:30 +00:00
|
|
|
import isMobile from 'ismobilejs'
|
2022-04-24 08:50:45 +00:00
|
|
|
import { reactive } from 'vue'
|
2022-09-15 09:07:25 +00:00
|
|
|
import { http } from '@/services'
|
2024-01-01 11:40:21 +00:00
|
|
|
import { playlistFolderStore, playlistStore, preferenceStore, queueStore, settingStore, themeStore, userStore } from '.'
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2022-04-24 08:50:45 +00:00
|
|
|
interface CommonStoreState {
|
2024-01-04 11:35:36 +00:00
|
|
|
allows_download: boolean
|
|
|
|
allows_upload: false,
|
2022-06-10 10:47:46 +00:00
|
|
|
cdn_url: string
|
|
|
|
current_user: User
|
|
|
|
current_version: string
|
|
|
|
latest_version: string
|
2024-01-04 11:35:36 +00:00
|
|
|
media_path_set: boolean
|
2022-04-15 14:24:30 +00:00
|
|
|
playlists: Playlist[]
|
2022-08-10 14:56:01 +00:00
|
|
|
playlist_folders: PlaylistFolder[]
|
2024-01-04 11:35:36 +00:00
|
|
|
queue_state: QueueState,
|
2022-04-15 14:24:30 +00:00
|
|
|
settings: Settings
|
2022-06-10 10:47:46 +00:00
|
|
|
song_count: number,
|
2024-01-01 11:40:21 +00:00
|
|
|
song_length: number,
|
2024-01-04 11:35:36 +00:00
|
|
|
uses_i_tunes: boolean
|
|
|
|
uses_last_fm: boolean
|
|
|
|
uses_spotify: boolean
|
|
|
|
uses_you_tube: boolean,
|
|
|
|
users: User[]
|
2022-04-15 14:24:30 +00:00
|
|
|
}
|
|
|
|
|
2022-04-24 08:50:45 +00:00
|
|
|
export const commonStore = {
|
|
|
|
state: reactive<CommonStoreState>({
|
2024-01-04 11:35:36 +00:00
|
|
|
allows_download: false,
|
|
|
|
allows_upload: false,
|
2022-06-10 10:47:46 +00:00
|
|
|
cdn_url: '',
|
|
|
|
current_user: undefined as unknown as User,
|
|
|
|
current_version: '',
|
|
|
|
latest_version: '',
|
2024-01-04 11:35:36 +00:00
|
|
|
media_path_set: false,
|
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,
|
2024-01-04 11:35:36 +00:00
|
|
|
uses_i_tunes: false,
|
|
|
|
uses_last_fm: false,
|
|
|
|
uses_spotify: false,
|
2022-04-15 14:24:30 +00:00
|
|
|
users: [],
|
2024-01-04 11:35:36 +00:00
|
|
|
uses_you_tube: false,
|
2022-06-10 10:47:46 +00:00
|
|
|
song_count: 0,
|
2024-01-01 11:40:21 +00:00
|
|
|
song_length: 0,
|
|
|
|
queue_state: {
|
|
|
|
type: 'queue-states',
|
|
|
|
songs: [],
|
|
|
|
current_song: null,
|
|
|
|
playback_position: 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 () {
|
2022-09-15 09:07:25 +00:00
|
|
|
Object.assign(this.state, await http.get<CommonStoreState>('data'))
|
2022-04-15 14:24:30 +00:00
|
|
|
|
|
|
|
// Always disable YouTube integration on mobile.
|
2024-01-04 11:35:36 +00:00
|
|
|
this.state.uses_you_tube = this.state.uses_you_tube && !isMobile.phone
|
|
|
|
|
|
|
|
// Always disable uploading on mobile
|
|
|
|
this.state.allows_upload = this.state.allows_upload && !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)
|
2024-01-01 11:40:21 +00:00
|
|
|
queueStore.init(this.state.queue_state)
|
2022-04-15 14:24:30 +00:00
|
|
|
themeStore.init()
|
|
|
|
|
|
|
|
return this.state
|
|
|
|
}
|
|
|
|
}
|