mirror of
https://github.com/qier222/YesPlayMusic.git
synced 2024-12-12 20:33:43 +08:00
19 lines
499 B
TypeScript
19 lines
499 B
TypeScript
|
import { Player } from '@/web/utils/player'
|
||
|
import { proxy, subscribe } from 'valtio'
|
||
|
|
||
|
const playerInLocalStorage = localStorage.getItem('player')
|
||
|
const player = proxy(new Player())
|
||
|
|
||
|
player.init((playerInLocalStorage && JSON.parse(playerInLocalStorage)) || {})
|
||
|
|
||
|
subscribe(player, () => {
|
||
|
localStorage.setItem('player', JSON.stringify(player))
|
||
|
})
|
||
|
|
||
|
if (import.meta.env.DEV) {
|
||
|
// eslint-disable-next-line @typescript-eslint/no-extra-semi
|
||
|
;(window as any).player = player
|
||
|
}
|
||
|
|
||
|
export default player
|