68 lines
1.7 KiB
TypeScript
68 lines
1.7 KiB
TypeScript
import Store from 'electron-store'
|
||
|
||
/** 应用配置结构(对应旧 electron-store 字段,做了类型化整理) */
|
||
export interface AppConfig {
|
||
/** 本地曲库根目录(http-server root) */
|
||
serverPath: string
|
||
/** HTTP 文件服务端口 */
|
||
serverPort: number
|
||
/** 歌曲源 URL(本地或远程),播放器与传输据此取流 */
|
||
url: string
|
||
/** 播放模式:order/repeat/single/shuffle */
|
||
playMode: 'order' | 'repeat' | 'single' | 'shuffle'
|
||
/** 音量 0-1 */
|
||
volume: number
|
||
/** 主题模式 */
|
||
theme: 'light' | 'dark' | 'system'
|
||
/** 主题强调色 */
|
||
accentColor: string
|
||
/** 数据版本(OSS data.json 版本) */
|
||
dataVersion: string
|
||
/** 上次播放列表(musicUId 数组) */
|
||
lastPlayList: string[]
|
||
/** 上次播放曲目 */
|
||
lastPlayId: string
|
||
/** 上次播放列表中的索引 */
|
||
lastPlayIndex: number
|
||
/** 上次播放进度(秒) */
|
||
lastProgress: number
|
||
/** 传输选中的歌曲 */
|
||
transMusic: string[]
|
||
/** 最近连接的手机系统 */
|
||
phoneSystem: string
|
||
}
|
||
|
||
const defaults: AppConfig = {
|
||
serverPath: '',
|
||
serverPort: 10000,
|
||
url: '',
|
||
playMode: 'order',
|
||
volume: 0.8,
|
||
theme: 'system',
|
||
accentColor: '#0A84FF',
|
||
dataVersion: '',
|
||
lastPlayList: [],
|
||
lastPlayId: '',
|
||
lastPlayIndex: 0,
|
||
lastProgress: 0,
|
||
transMusic: [],
|
||
phoneSystem: ''
|
||
}
|
||
|
||
let store: Store<AppConfig> | null = null
|
||
|
||
export function getStore(): Store<AppConfig> {
|
||
if (!store) {
|
||
store = new Store<AppConfig>({ name: 'config', defaults })
|
||
}
|
||
return store
|
||
}
|
||
|
||
export function getConfig<K extends keyof AppConfig>(key: K): AppConfig[K] {
|
||
return getStore().get(key)
|
||
}
|
||
|
||
export function setConfig<K extends keyof AppConfig>(key: K, value: AppConfig[K]): void {
|
||
getStore().set(key, value)
|
||
}
|