This repository has been archived by the owner on Oct 9, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 41
/
shared.ts
89 lines (79 loc) · 2.27 KB
/
shared.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import isMobile from 'ismobilejs'
import { http } from '@/services'
import {
userStore,
preferenceStore,
artistStore,
albumStore,
songStore,
playlistStore,
recentlyPlayedStore,
queueStore,
settingStore
} from '.'
interface SharedState {
albums: Album[]
allowDownload: boolean
artists: Artist[]
cdnUrl: string
currentUser: User | null
currentVersion: string
favorites: Song[]
interactions: Interaction[]
latestVersion: string
originalMediaPath: string | undefined
playlists: Playlist[]
queued: Song[]
recentlyPlayed: string[]
settings: Settings
songs: Song[]
useiTunes: boolean
useLastfm: boolean
users: User[]
useYouTube: boolean
}
export const sharedStore = {
state: {
albums: [],
allowDownload: false,
artists: [],
cdnUrl: '',
currentUser: null as User | null,
currentVersion: '',
favorites: [],
interactions: [],
latestVersion: '',
originalMediaPath: '',
playlists: [],
queued: [],
recentlyPlayed: [],
settings: {} as Settings,
songs: [],
useiTunes: false,
useLastfm: false,
users: [],
useYouTube: false
},
async init (): Promise<SharedState> {
this.state = Object.assign(this.state, await http.get<SharedState>('data'))
// Don't allow downloading on mobile devices
this.state.allowDownload = this.state.allowDownload && !isMobile.any
// Always disable YouTube integration on mobile.
this.state.useYouTube = this.state.useYouTube && !isMobile.phone
// If this is a new user, initialize his preferences to be an empty object.
this.state.currentUser!.preferences = this.state.currentUser!.preferences || {}
userStore.init(this.state.users, this.state.currentUser!)
preferenceStore.init(this.state.currentUser)
artistStore.init(this.state.artists)
albumStore.init(this.state.albums)
songStore.init(this.state.songs)
songStore.initInteractions(this.state.interactions)
recentlyPlayedStore.initExcerpt(this.state.recentlyPlayed)
playlistStore.init(this.state.playlists)
queueStore.init()
settingStore.init(this.state.settings)
// Keep a copy of the media path. We'll need this to properly warn the user later.
this.state.originalMediaPath = this.state.settings.media_path!
return this.state
}
}