mirror of
https://github.com/algerkong/AlgerMusicPlayer.git
synced 2026-04-03 14:20:50 +08:00
feat(config): 添加GPU加速设置支持
This commit is contained in:
@@ -50,7 +50,15 @@ export default {
|
||||
englishText: 'The quick brown fox jumps over the lazy dog',
|
||||
japaneseText: 'あいうえお かきくけこ さしすせそ',
|
||||
koreanText: '가나다라마 바사아자차 카타파하'
|
||||
}
|
||||
},
|
||||
gpuAcceleration: 'GPU Acceleration',
|
||||
gpuAccelerationDesc:
|
||||
'Enable or disable hardware acceleration, can improve rendering performance but may increase GPU load',
|
||||
gpuAccelerationRestart:
|
||||
'Changing GPU acceleration settings requires application restart to take effect',
|
||||
gpuAccelerationChangeSuccess:
|
||||
'GPU acceleration settings updated, restart application to take effect',
|
||||
gpuAccelerationChangeError: 'Failed to update GPU acceleration settings'
|
||||
},
|
||||
playback: {
|
||||
quality: 'Audio Quality',
|
||||
|
||||
@@ -50,7 +50,14 @@ export default {
|
||||
englishText: 'The quick brown fox jumps over the lazy dog',
|
||||
japaneseText: 'あいうえお かきくけこ さしすせそ',
|
||||
koreanText: '가나다라마 바사아자차 카타파하'
|
||||
}
|
||||
},
|
||||
gpuAcceleration: 'GPUアクセラレーション',
|
||||
gpuAccelerationDesc:
|
||||
'ハードウェアアクセラレーションを有効または無効にします。レンダリングパフォーマンスを向上させますが、GPU負荷が増える可能性があります',
|
||||
gpuAccelerationRestart: 'GPUアクセラレーション設定の変更はアプリの再起動後に有効になります',
|
||||
gpuAccelerationChangeSuccess:
|
||||
'GPUアクセラレーション設定を更新しました。アプリの再起動後に有効になります',
|
||||
gpuAccelerationChangeError: 'GPUアクセラレーション設定の更新に失敗しました'
|
||||
},
|
||||
playback: {
|
||||
quality: '音質設定',
|
||||
|
||||
@@ -50,7 +50,14 @@ export default {
|
||||
englishText: 'The quick brown fox jumps over the lazy dog',
|
||||
japaneseText: 'あいうえお かきくけこ さしすせそ',
|
||||
koreanText: '가나다라마 바사아자차 카타파하'
|
||||
}
|
||||
},
|
||||
gpuAcceleration: 'GPU 가속',
|
||||
gpuAccelerationDesc:
|
||||
'GPU 가속을 사용하면 애니메이션이 빠르게 재생되고 애니메이션이 느리게 재생되는 것보다 느릴 수 있습니다.',
|
||||
gpuAccelerationRestart: 'GPU 가속 설정을 변경하면 애플리케이션을 다시 시작해야 합니다',
|
||||
gpuAccelerationChangeSuccess:
|
||||
'GPU 가속 설정이 업데이트되었습니다. 애플리케이션을 다시 시작하여 적용하십시오',
|
||||
gpuAccelerationChangeError: 'GPU 가속 설정 업데이트에 실패했습니다'
|
||||
},
|
||||
playback: {
|
||||
quality: '음질 설정',
|
||||
|
||||
@@ -50,7 +50,12 @@ export default {
|
||||
englishText: 'The quick brown fox jumps over the lazy dog',
|
||||
japaneseText: 'あいうえお かきくけこ さしすせそ',
|
||||
koreanText: '가나다라마 바사아자차 카타파하'
|
||||
}
|
||||
},
|
||||
gpuAcceleration: 'GPU加速',
|
||||
gpuAccelerationDesc: '启用或禁用硬件加速,可以提高渲染性能但可能会增加GPU负载',
|
||||
gpuAccelerationRestart: '更改GPU加速设置需要重启应用后生效',
|
||||
gpuAccelerationChangeSuccess: 'GPU加速设置已更新,重启应用后生效',
|
||||
gpuAccelerationChangeError: 'GPU加速设置更新失败'
|
||||
},
|
||||
playback: {
|
||||
quality: '音质设置',
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -31,5 +31,6 @@
|
||||
"manualTheme": "light",
|
||||
"isMenuExpanded": false,
|
||||
"customApiPlugin": "",
|
||||
"customApiPluginName": ""
|
||||
"customApiPluginName": "",
|
||||
"enableGpuAcceleration": true
|
||||
}
|
||||
|
||||
@@ -197,6 +197,29 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- GPU加速设置 -->
|
||||
<div class="set-item" v-if="isElectron">
|
||||
<div>
|
||||
<div class="set-item-title">{{ t('settings.basic.gpuAcceleration') }}</div>
|
||||
<div class="set-item-content">
|
||||
<div class="text-sm text-gray-500 mb-2">
|
||||
{{ t('settings.basic.gpuAccelerationDesc') }}
|
||||
</div>
|
||||
<div class="text-xs text-amber-500" v-if="gpuAccelerationChanged">
|
||||
<i class="ri-information-line mr-1"></i>
|
||||
{{ t('settings.basic.gpuAccelerationRestart') }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<n-switch
|
||||
v-model:value="setData.enableGpuAcceleration"
|
||||
@update:value="handleGpuAccelerationChange"
|
||||
>
|
||||
<template #checked><i class="ri-cpu-line"></i></template>
|
||||
<template #unchecked><i class="ri-cpu-line"></i></template>
|
||||
</n-switch>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -680,6 +703,33 @@ const handleAutoThemeChange = (value: boolean) => {
|
||||
settingsStore.setAutoTheme(value);
|
||||
};
|
||||
|
||||
// GPU加速相关
|
||||
const gpuAccelerationChanged = ref(false);
|
||||
|
||||
/**
|
||||
* 处理GPU加速设置变更
|
||||
* 在非Electron环境下,直接更新配置
|
||||
* 在Electron环境下,通过IPC通信更新主进程配置并提示重启
|
||||
*/
|
||||
const handleGpuAccelerationChange = (enabled: boolean) => {
|
||||
try {
|
||||
if (window.electron) {
|
||||
// Electron环境:通过IPC更新主进程配置
|
||||
window.electron.ipcRenderer.send('update-gpu-acceleration', enabled);
|
||||
gpuAccelerationChanged.value = true;
|
||||
|
||||
// 显示重启提示
|
||||
message.info(t('settings.basic.gpuAccelerationChangeSuccess'));
|
||||
} else {
|
||||
// 非Electron环境:直接更新本地配置
|
||||
console.log('GPU加速设置在Web环境下不生效');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('GPU加速设置更新失败:', error);
|
||||
message.error(t('settings.basic.gpuAccelerationChangeError'));
|
||||
}
|
||||
};
|
||||
|
||||
const openAuthor = () => {
|
||||
window.open(setData.value.authorUrl);
|
||||
};
|
||||
@@ -795,6 +845,21 @@ onMounted(async () => {
|
||||
enableRealIP: false
|
||||
};
|
||||
}
|
||||
|
||||
// 监听GPU加速设置更新事件
|
||||
if (window.electron) {
|
||||
// 监听更新成功事件
|
||||
window.electron.ipcRenderer.on('gpu-acceleration-updated', (_, enabled: boolean) => {
|
||||
console.log('GPU加速设置已更新:', enabled);
|
||||
gpuAccelerationChanged.value = true;
|
||||
});
|
||||
|
||||
// 监听更新错误事件
|
||||
window.electron.ipcRenderer.on('gpu-acceleration-update-error', (_, errorMessage: string) => {
|
||||
console.error('GPU加速设置更新错误:', errorMessage);
|
||||
gpuAccelerationChanged.value = false;
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// 监听代理配置变化
|
||||
|
||||
Reference in New Issue
Block a user