mirror of
https://github.com/GiriNeko/YesPlayMusic.git
synced 2025-12-17 13:48:02 +00:00
feat: updates
This commit is contained in:
parent
0b4baa3eff
commit
222fb02355
77 changed files with 654 additions and 551 deletions
19
packages/web/states/persistedUiStates.ts
Normal file
19
packages/web/states/persistedUiStates.ts
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
import { proxy, subscribe } from 'valtio'
|
||||
|
||||
interface PersistedUiStates {
|
||||
loginPhoneCountryCode: string
|
||||
loginType: 'phone' | 'email' | 'qrCode'
|
||||
}
|
||||
|
||||
const initPersistedUiStates: PersistedUiStates = {
|
||||
loginPhoneCountryCode: '+86',
|
||||
loginType: 'qrCode',
|
||||
}
|
||||
|
||||
const persistedUiStates = proxy<PersistedUiStates>(initPersistedUiStates)
|
||||
|
||||
subscribe(persistedUiStates, () => {
|
||||
localStorage.setItem('persistedUiStates', JSON.stringify(persistedUiStates))
|
||||
})
|
||||
|
||||
export default persistedUiStates
|
||||
18
packages/web/states/player.ts
Normal file
18
packages/web/states/player.ts
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
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
|
||||
61
packages/web/states/scrollPositions.ts
Normal file
61
packages/web/states/scrollPositions.ts
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
class ScrollPositions {
|
||||
private _nestedPaths: string[] = ['/artist', '/album', '/playlist', '/search']
|
||||
private _positions: Record<string, { path: string; top: number }[]> = {}
|
||||
private _generalPositions: Record<string, number> = {}
|
||||
|
||||
constructor() {
|
||||
this._nestedPaths.forEach(path => (this._positions[path] = []))
|
||||
}
|
||||
|
||||
get(pathname: string) {
|
||||
const nestedPath = `/${pathname.split('/')[1]}`
|
||||
const restPath = pathname.split('/').slice(2).join('/')
|
||||
if (this._nestedPaths.includes(nestedPath)) {
|
||||
return this._positions?.[nestedPath]?.find(
|
||||
({ path }) => path === restPath
|
||||
)?.top
|
||||
} else {
|
||||
return this._generalPositions?.[pathname]
|
||||
}
|
||||
}
|
||||
|
||||
set(pathname: string, top: number) {
|
||||
console.log('set', pathname, top)
|
||||
const nestedPath = `/${pathname.split('/')[1]}`
|
||||
const restPath = pathname.split('/').slice(2).join('/')
|
||||
|
||||
// set general position
|
||||
if (!this._nestedPaths.includes(nestedPath)) {
|
||||
this._generalPositions[pathname] = top
|
||||
return
|
||||
}
|
||||
|
||||
// set nested position
|
||||
const existsPath = this._positions[nestedPath].find(
|
||||
p => p.path === restPath
|
||||
)
|
||||
if (existsPath) {
|
||||
existsPath.top = top
|
||||
this._positions[nestedPath] = this._positions[nestedPath].filter(
|
||||
p => p.path !== restPath
|
||||
)
|
||||
this._positions[nestedPath].push(existsPath)
|
||||
} else {
|
||||
this._positions[nestedPath].push({ path: restPath, top })
|
||||
}
|
||||
|
||||
// delete oldest position when there are more than 10
|
||||
if (this._positions[nestedPath].length > 10) {
|
||||
this._positions[nestedPath].shift()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const scrollPositions = new ScrollPositions()
|
||||
|
||||
if (import.meta.env.DEV) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-extra-semi
|
||||
;(window as any).scrollPositions = scrollPositions
|
||||
}
|
||||
|
||||
export default scrollPositions
|
||||
53
packages/web/states/settings.ts
Normal file
53
packages/web/states/settings.ts
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
import { IpcChannels } from '@/shared/IpcChannels'
|
||||
import { merge } from 'lodash-es'
|
||||
import { proxy, subscribe } from 'valtio'
|
||||
|
||||
interface Settings {
|
||||
accentColor: string
|
||||
unm: {
|
||||
enabled: boolean
|
||||
sources: Array<
|
||||
'migu' | 'kuwo' | 'kugou' | 'ytdl' | 'qq' | 'bilibili' | 'joox'
|
||||
>
|
||||
searchMode: 'order-first' | 'fast-first'
|
||||
proxy: null | {
|
||||
protocol: 'http' | 'https' | 'socks5'
|
||||
host: string
|
||||
port: number
|
||||
username?: string
|
||||
password?: string
|
||||
}
|
||||
cookies: {
|
||||
qq?: string
|
||||
joox?: string
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const initSettings: Settings = {
|
||||
accentColor: 'blue',
|
||||
unm: {
|
||||
enabled: true,
|
||||
sources: ['migu'],
|
||||
searchMode: 'order-first',
|
||||
proxy: null,
|
||||
cookies: {},
|
||||
},
|
||||
}
|
||||
|
||||
const settingsInLocalStorage = localStorage.getItem('settings')
|
||||
const settings = proxy<Settings>(
|
||||
merge(
|
||||
initSettings,
|
||||
settingsInLocalStorage ? JSON.parse(settingsInLocalStorage) : {}
|
||||
)
|
||||
)
|
||||
|
||||
subscribe(settings, () => {
|
||||
localStorage.setItem('settings', JSON.stringify(settings))
|
||||
})
|
||||
subscribe(settings, () => {
|
||||
window.ipcRenderer?.send(IpcChannels.SyncSettings, settings)
|
||||
})
|
||||
|
||||
export default settings
|
||||
19
packages/web/states/uiStates.ts
Normal file
19
packages/web/states/uiStates.ts
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
import { proxy } from 'valtio'
|
||||
|
||||
interface UIStates {
|
||||
showLyricPanel: boolean
|
||||
showLoginPanel: boolean
|
||||
hideTopbarBackground: boolean
|
||||
librarySelectedTab: 'playlists' | 'albums' | 'artists' | 'videos'
|
||||
mobileShowPlayingNext: boolean
|
||||
}
|
||||
|
||||
const initUIStates: UIStates = {
|
||||
showLyricPanel: false,
|
||||
showLoginPanel: false,
|
||||
hideTopbarBackground: false,
|
||||
librarySelectedTab: 'playlists',
|
||||
mobileShowPlayingNext: false,
|
||||
}
|
||||
|
||||
export default proxy<UIStates>(initUIStates)
|
||||
Loading…
Add table
Add a link
Reference in a new issue