koel/resources/assets/js/stores/commonStore.ts

62 lines
1.7 KiB
TypeScript
Raw Normal View History

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 { http } from '@/services'
import { playlistFolderStore, playlistStore, preferenceStore, queueStore, settingStore, themeStore, userStore } from '.'
2022-04-15 14:24:30 +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: {
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
},
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-07-05 12:20:30 +00:00
songs: [],
current_song: null,
playback_position: 0
} as QueueState,
supports_batch_downloading: false
2022-04-15 14:24:30 +00:00
}
type CommonStoreState = typeof initialState
2022-04-24 08:50:45 +00:00
export const commonStore = {
state: reactive<CommonStoreState>(initialState),
2022-04-15 14:24:30 +00:00
2022-04-24 08:50:45 +00:00
async init () {
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)
preferenceStore.init(this.state.current_user.preferences)
2022-04-15 14:24:30 +00:00
playlistStore.init(this.state.playlists)
playlistFolderStore.init(this.state.playlist_folders)
2022-04-15 14:24:30 +00:00
settingStore.init(this.state.settings)
queueStore.init(this.state.queue_state)
2022-04-15 14:24:30 +00:00
themeStore.init()
return this.state
}
}