mirror of
https://github.com/algerkong/AlgerMusicPlayer.git
synced 2026-04-14 14:50:50 +08:00
65 lines
1.3 KiB
TypeScript
65 lines
1.3 KiB
TypeScript
import { app, ipcMain } from 'electron';
|
|
import Store from 'electron-store';
|
|
|
|
import set from '../set.json';
|
|
import { defaultShortcuts } from './shortcuts';
|
|
|
|
type SetConfig = {
|
|
isProxy: boolean;
|
|
proxyConfig: {
|
|
enable: boolean;
|
|
protocol: string;
|
|
host: string;
|
|
port: number;
|
|
};
|
|
enableRealIP: boolean;
|
|
realIP: string;
|
|
noAnimate: boolean;
|
|
animationSpeed: number;
|
|
author: string;
|
|
authorUrl: string;
|
|
musicApiPort: number;
|
|
closeAction: 'ask' | 'minimize' | 'close';
|
|
musicQuality: string;
|
|
fontFamily: string;
|
|
fontScope: 'global' | 'lyric';
|
|
language: string;
|
|
};
|
|
interface StoreType {
|
|
set: SetConfig;
|
|
shortcuts: typeof defaultShortcuts;
|
|
}
|
|
|
|
let store: Store<StoreType>;
|
|
|
|
/**
|
|
* 初始化配置管理
|
|
*/
|
|
export function initializeConfig() {
|
|
store = new Store<StoreType>({
|
|
name: 'config',
|
|
defaults: {
|
|
set: set as SetConfig,
|
|
shortcuts: defaultShortcuts
|
|
}
|
|
});
|
|
|
|
store.get('set.downloadPath') || store.set('set.downloadPath', app.getPath('downloads'));
|
|
|
|
// 定义ipcRenderer监听事件
|
|
ipcMain.on('set-store-value', (_, key, value) => {
|
|
store.set(key, value);
|
|
});
|
|
|
|
ipcMain.on('get-store-value', (_, key) => {
|
|
const value = store.get(key);
|
|
_.returnValue = value || '';
|
|
});
|
|
|
|
return store;
|
|
}
|
|
|
|
export function getStore() {
|
|
return store;
|
|
}
|