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 | null = null export function getStore(): Store { if (!store) { store = new Store({ name: 'config', defaults }) } return store } export function getConfig(key: K): AppConfig[K] { return getStore().get(key) } export function setConfig(key: K, value: AppConfig[K]): void { getStore().set(key, value) }