2025-01-02 00:14:05 +08:00
|
|
|
|
import { app, ipcMain } from 'electron';
|
|
|
|
|
|
import Store from 'electron-store';
|
2026-03-06 19:56:01 +08:00
|
|
|
|
import * as path from 'path';
|
2025-01-10 22:49:55 +08:00
|
|
|
|
|
2026-03-04 20:28:38 +08:00
|
|
|
|
import { createDefaultShortcuts, type ShortcutsConfig } from '../../shared/shortcuts';
|
2025-01-02 00:14:05 +08:00
|
|
|
|
import set from '../set.json';
|
|
|
|
|
|
|
2025-01-18 03:25:21 +08:00
|
|
|
|
type SetConfig = {
|
|
|
|
|
|
isProxy: boolean;
|
|
|
|
|
|
proxyConfig: {
|
|
|
|
|
|
enable: boolean;
|
|
|
|
|
|
protocol: string;
|
|
|
|
|
|
host: string;
|
|
|
|
|
|
port: number;
|
2025-01-02 00:14:05 +08:00
|
|
|
|
};
|
2025-01-18 03:25:21 +08:00
|
|
|
|
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';
|
2025-01-23 11:02:55 +08:00
|
|
|
|
language: string;
|
2025-05-17 14:45:39 +08:00
|
|
|
|
showTopAction: boolean;
|
2025-09-20 16:51:47 +08:00
|
|
|
|
enableGpuAcceleration: boolean;
|
2026-03-06 19:56:01 +08:00
|
|
|
|
downloadPath: string;
|
|
|
|
|
|
enableDiskCache: boolean;
|
|
|
|
|
|
diskCacheDir: string;
|
|
|
|
|
|
diskCacheMaxSizeMB: number;
|
|
|
|
|
|
diskCacheCleanupPolicy: 'lru' | 'fifo';
|
2025-01-18 03:25:21 +08:00
|
|
|
|
};
|
|
|
|
|
|
interface StoreType {
|
|
|
|
|
|
set: SetConfig;
|
2026-03-04 20:28:38 +08:00
|
|
|
|
shortcuts: ShortcutsConfig;
|
2025-01-02 00:14:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
let store: Store<StoreType>;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 初始化配置管理
|
|
|
|
|
|
*/
|
|
|
|
|
|
export function initializeConfig() {
|
|
|
|
|
|
store = new Store<StoreType>({
|
|
|
|
|
|
name: 'config',
|
|
|
|
|
|
defaults: {
|
2025-01-18 03:25:21 +08:00
|
|
|
|
set: set as SetConfig,
|
2026-03-04 20:28:38 +08:00
|
|
|
|
shortcuts: createDefaultShortcuts()
|
2025-01-02 00:14:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
store.get('set.downloadPath') || store.set('set.downloadPath', app.getPath('downloads'));
|
2026-03-06 19:56:01 +08:00
|
|
|
|
store.get('set.diskCacheDir') ||
|
|
|
|
|
|
store.set('set.diskCacheDir', path.join(app.getPath('userData'), 'cache'));
|
|
|
|
|
|
if (store.get('set.diskCacheMaxSizeMB') === undefined) {
|
|
|
|
|
|
store.set('set.diskCacheMaxSizeMB', 4096);
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!store.get('set.diskCacheCleanupPolicy')) {
|
|
|
|
|
|
store.set('set.diskCacheCleanupPolicy', 'lru');
|
|
|
|
|
|
}
|
|
|
|
|
|
if (store.get('set.enableDiskCache') === undefined) {
|
|
|
|
|
|
store.set('set.enableDiskCache', true);
|
|
|
|
|
|
}
|
2025-01-02 00:14:05 +08:00
|
|
|
|
|
|
|
|
|
|
// 定义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 || '';
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2025-09-20 16:51:47 +08:00
|
|
|
|
// GPU加速设置更新处理
|
|
|
|
|
|
// 注意:GPU加速设置必须在应用启动时在app.ready之前设置才能生效
|
|
|
|
|
|
ipcMain.on('update-gpu-acceleration', (event, enabled: boolean) => {
|
|
|
|
|
|
try {
|
|
|
|
|
|
console.log('GPU加速设置更新:', enabled);
|
|
|
|
|
|
store.set('set.enableGpuAcceleration', enabled);
|
|
|
|
|
|
|
|
|
|
|
|
// GPU加速设置需要重启应用才能生效
|
|
|
|
|
|
event.sender.send('gpu-acceleration-updated', enabled);
|
|
|
|
|
|
console.log('GPU加速设置已保存,重启应用后生效');
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
console.error('GPU加速设置更新失败:', error);
|
|
|
|
|
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
|
|
|
|
event.sender.send('gpu-acceleration-update-error', errorMessage);
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2025-01-02 00:14:05 +08:00
|
|
|
|
return store;
|
2025-01-10 22:49:55 +08:00
|
|
|
|
}
|
2025-01-15 00:30:00 +08:00
|
|
|
|
|
|
|
|
|
|
export function getStore() {
|
|
|
|
|
|
return store;
|
|
|
|
|
|
}
|