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
|
|
|
|
2024-02-09 15:45:38 +00:00
|
|
|
const initialState = {
|
|
|
|
allows_download: false,
|
|
|
|
cdn_url: '',
|
|
|
|
current_user: undefined as unknown as User,
|
|
|
|
current_version: '',
|
2024-01-08 16:59:05 +00:00
|
|
|
koel_plus: {
|
2024-02-09 15:45:38 +00:00
|
|
|
active: false,
|
2024-02-25 19:32:53 +00:00
|
|
|
short_key: null as string | null,
|
|
|
|
customer_name: null as string | null,
|
|
|
|
customer_email: null as string | null,
|
|
|
|
product_id: '' as string | null
|
2024-02-09 15:45:38 +00:00
|
|
|
},
|
|
|
|
latest_version: '',
|
|
|
|
media_path_set: false,
|
|
|
|
playlists: [] as Playlist[],
|
|
|
|
playlist_folders: [] as PlaylistFolder[],
|
|
|
|
settings: {} as Settings,
|
|
|
|
uses_i_tunes: false,
|
|
|
|
uses_last_fm: false,
|
|
|
|
uses_spotify: false,
|
|
|
|
users: [] as User[],
|
|
|
|
uses_you_tube: false,
|
|
|
|
storage_driver: 'local',
|
|
|
|
song_count: 0,
|
|
|
|
song_length: 0,
|
|
|
|
queue_state: {
|
|
|
|
type: 'queue-states',
|
2024-06-02 17:15:31 +00:00
|
|
|
playables: [],
|
2024-02-09 15:45:38 +00:00
|
|
|
current_song: null,
|
|
|
|
playback_position: 0
|
|
|
|
} as QueueState
|
2022-04-15 14:24:30 +00:00
|
|
|
}
|
|
|
|
|
2024-02-09 15:45:38 +00:00
|
|
|
type CommonStoreState = typeof initialState
|
|
|
|
|
2022-04-24 08:50:45 +00:00
|
|
|
export const commonStore = {
|
2024-02-09 15:45:38 +00:00
|
|
|
state: reactive<CommonStoreState>(initialState),
|
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
|
|
|
|
|
2022-06-10 10:47:46 +00:00
|
|
|
userStore.init(this.state.current_user)
|
2024-02-09 15:45:38 +00:00
|
|
|
preferenceStore.init(this.state.current_user.preferences)
|
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
|
|
|
|
}
|
|
|
|
}
|