mirror of
https://github.com/GiriNeko/YesPlayMusic.git
synced 2025-12-17 21:58:03 +00:00
feat: updates
This commit is contained in:
parent
f340a90117
commit
cec4c5909d
50 changed files with 1304 additions and 207 deletions
35
packages/web/store/index.ts
Normal file
35
packages/web/store/index.ts
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
import { proxy, subscribe } from 'valtio'
|
||||
import { Player } from '@/web/utils/player'
|
||||
import { merge } from 'lodash-es'
|
||||
import { IpcChannels } from '@/shared/IpcChannels'
|
||||
import { Store, initialState } from '@/shared/store'
|
||||
|
||||
const stateInLocalStorage = localStorage.getItem('state')
|
||||
export const state = proxy<Store>(
|
||||
merge(
|
||||
initialState,
|
||||
stateInLocalStorage ? JSON.parse(stateInLocalStorage) : {},
|
||||
{
|
||||
uiStates: initialState.uiStates,
|
||||
}
|
||||
)
|
||||
)
|
||||
subscribe(state, () => {
|
||||
localStorage.setItem('state', JSON.stringify(state))
|
||||
})
|
||||
subscribe(state.settings, () => {
|
||||
window.ipcRenderer?.send(IpcChannels.SyncSettings, { ...state.settings })
|
||||
})
|
||||
|
||||
// player
|
||||
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) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-extra-semi
|
||||
;(window as any).player = player
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue