mirror of
https://github.com/algerkong/AlgerMusicPlayer.git
synced 2026-04-23 23:57:22 +08:00
feat(config): 添加GPU加速设置支持
This commit is contained in:
+26
-6
@@ -9,6 +9,7 @@ import { initializeConfig } from './modules/config';
|
||||
import { initializeFileManager } from './modules/fileManager';
|
||||
import { initializeFonts } from './modules/fonts';
|
||||
import { initializeLoginWindow } from './modules/loginWindow';
|
||||
import { initializeOtherApi } from './modules/otherApi';
|
||||
import { initializeRemoteControl } from './modules/remoteControl';
|
||||
import { initializeShortcuts, registerShortcuts } from './modules/shortcuts';
|
||||
import { initializeTray, updateCurrentSong, updatePlayState, updateTrayMenu } from './modules/tray';
|
||||
@@ -16,7 +17,6 @@ import { setupUpdateHandlers } from './modules/update';
|
||||
import { createMainWindow, initializeWindowManager, setAppQuitting } from './modules/window';
|
||||
import { initWindowSizeManager } from './modules/window-size';
|
||||
import { startMusicApi } from './server';
|
||||
import { initializeOtherApi } from './modules/otherApi';
|
||||
|
||||
// 导入所有图标
|
||||
const iconPath = join(__dirname, '../../resources');
|
||||
@@ -27,9 +27,9 @@ const icon = nativeImage.createFromPath(
|
||||
let mainWindow: Electron.BrowserWindow;
|
||||
|
||||
// 初始化应用
|
||||
function initialize() {
|
||||
// 初始化配置管理
|
||||
const store = initializeConfig();
|
||||
function initialize(configStore: any) {
|
||||
// 使用已初始化的配置存储
|
||||
const store = configStore;
|
||||
|
||||
// 设置初始语言
|
||||
const savedLanguage = store.get('set.language') as Language;
|
||||
@@ -76,6 +76,23 @@ const isSingleInstance = app.requestSingleInstanceLock();
|
||||
if (!isSingleInstance) {
|
||||
app.quit();
|
||||
} else {
|
||||
// 在应用准备就绪前初始化GPU加速设置
|
||||
// 必须在 app.ready 之前调用 disableHardwareAcceleration
|
||||
try {
|
||||
// 初始化配置管理以获取GPU加速设置
|
||||
const store = initializeConfig();
|
||||
const enableGpuAcceleration = store.get('set.enableGpuAcceleration', true) as boolean;
|
||||
|
||||
if (!enableGpuAcceleration) {
|
||||
console.log('GPU加速已禁用');
|
||||
app.disableHardwareAcceleration();
|
||||
} else {
|
||||
console.log('GPU加速已启用');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('GPU加速设置初始化失败:', error);
|
||||
// 如果配置读取失败,默认启用GPU加速
|
||||
}
|
||||
// 当第二个实例启动时,将焦点转移到第一个实例的窗口
|
||||
app.on('second-instance', () => {
|
||||
if (mainWindow) {
|
||||
@@ -100,12 +117,15 @@ if (!isSingleInstance) {
|
||||
// 初始化窗口大小管理器
|
||||
initWindowSizeManager();
|
||||
|
||||
// 重新初始化配置管理以获取完整的配置存储
|
||||
const store = initializeConfig();
|
||||
|
||||
// 初始化应用
|
||||
initialize();
|
||||
initialize(store);
|
||||
|
||||
// macOS 激活应用时的处理
|
||||
app.on('activate', () => {
|
||||
if (mainWindow === null) initialize();
|
||||
if (mainWindow === null) initialize(store);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ type SetConfig = {
|
||||
fontScope: 'global' | 'lyric';
|
||||
language: string;
|
||||
showTopAction: boolean;
|
||||
enableGpuAcceleration: boolean;
|
||||
};
|
||||
interface StoreType {
|
||||
set: SetConfig;
|
||||
@@ -57,6 +58,23 @@ export function initializeConfig() {
|
||||
_.returnValue = value || '';
|
||||
});
|
||||
|
||||
// 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);
|
||||
}
|
||||
});
|
||||
|
||||
return store;
|
||||
}
|
||||
|
||||
|
||||
+2
-1
@@ -31,5 +31,6 @@
|
||||
"manualTheme": "light",
|
||||
"isMenuExpanded": false,
|
||||
"customApiPlugin": "",
|
||||
"customApiPluginName": ""
|
||||
"customApiPluginName": "",
|
||||
"enableGpuAcceleration": true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user