feat: updates

This commit is contained in:
qier222 2022-08-03 23:48:39 +08:00
parent 47e41dea9b
commit ebebf2a733
No known key found for this signature in database
GPG key ID: 9C85007ED905F14D
160 changed files with 4148 additions and 2001 deletions

View file

@ -1,19 +1,35 @@
import { merge } from 'lodash-es'
import { proxy, subscribe } from 'valtio'
interface PersistedUiStates {
loginPhoneCountryCode: string
loginType: 'phone' | 'email' | 'qrCode'
minimizePlayer: boolean
}
const initPersistedUiStates: PersistedUiStates = {
loginPhoneCountryCode: '+86',
loginType: 'qrCode',
minimizePlayer: false,
}
const persistedUiStates = proxy<PersistedUiStates>(initPersistedUiStates)
const STORAGE_KEY = 'persistedUiStates'
const statesInStorage = localStorage.getItem(STORAGE_KEY)
let sates = {}
if (statesInStorage) {
try {
sates = JSON.parse(statesInStorage)
} catch {
// ignore
}
}
const persistedUiStates = proxy<PersistedUiStates>(
merge(initPersistedUiStates, sates)
)
subscribe(persistedUiStates, () => {
localStorage.setItem('persistedUiStates', JSON.stringify(persistedUiStates))
localStorage.setItem(STORAGE_KEY, JSON.stringify(persistedUiStates))
})
export default persistedUiStates

View file

@ -35,19 +35,22 @@ const initSettings: Settings = {
},
}
const settingsInLocalStorage = localStorage.getItem('settings')
const settings = proxy<Settings>(
merge(
initSettings,
settingsInLocalStorage ? JSON.parse(settingsInLocalStorage) : {}
)
)
const STORAGE_KEY = 'settings'
const statesInStorageString = localStorage.getItem(STORAGE_KEY)
let statesInStorage = {}
if (statesInStorageString) {
try {
statesInStorage = JSON.parse(statesInStorageString)
} catch {
// ignore
}
}
const settings = proxy<Settings>(merge(initSettings, statesInStorage))
subscribe(settings, () => {
localStorage.setItem('settings', JSON.stringify(settings))
})
subscribe(settings, () => {
window.ipcRenderer?.send(IpcChannels.SyncSettings, settings)
localStorage.setItem(STORAGE_KEY, JSON.stringify(settings))
})
export default settings

View file

@ -1,3 +1,4 @@
import { IpcChannels } from '@/shared/IpcChannels'
import { proxy } from 'valtio'
interface UIStates {
@ -6,6 +7,8 @@ interface UIStates {
hideTopbarBackground: boolean
librarySelectedTab: 'playlists' | 'albums' | 'artists' | 'videos'
mobileShowPlayingNext: boolean
blurBackgroundImage: string | null
fullscreen: boolean
}
const initUIStates: UIStates = {
@ -14,6 +17,8 @@ const initUIStates: UIStates = {
hideTopbarBackground: false,
librarySelectedTab: 'playlists',
mobileShowPlayingNext: false,
blurBackgroundImage: null,
fullscreen: window.ipcRenderer?.sendSync(IpcChannels.IsMaximized) || false,
}
export default proxy<UIStates>(initUIStates)