feat: 保存player状态到本地存储

This commit is contained in:
qier222 2022-04-05 23:02:37 +08:00
parent 49bb849982
commit abedbe7531
No known key found for this signature in database
GPG key ID: 9C85007ED905F14D
2 changed files with 27 additions and 10 deletions

View file

@ -1,6 +1,6 @@
import { proxy, subscribe } from 'valtio'
import { devtools } from 'valtio/utils'
import { player as PlayerCore } from '@/utils/player'
import { Player } from '@/utils/player'
interface Store {
uiStates: {
@ -28,8 +28,12 @@ subscribe(state, () => {
localStorage.setItem('state', JSON.stringify(state))
})
export const player = proxy(PlayerCore)
player.init()
const playerInLocalStorage = localStorage.getItem('player')
export const player = proxy(new Player())
player.init((playerInLocalStorage && JSON.parse(playerInLocalStorage)) || {})
subscribe(player, () => {
localStorage.setItem('player', JSON.stringify(player))
})
if (import.meta.env.DEV) {
;(window as any).player = player