diff --git a/src/main/index.ts b/src/main/index.ts index e102775..6efdc36 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -199,6 +199,21 @@ function getSystemLanguage(): 'zh-CN' | 'en-US' { return locale.startsWith('zh') ? 'zh-CN' : 'en-US' } +// 硬件加速设置 +async function initHardwareAcceleration(): Promise { + try { + await initBasic() + const { disableHardwareAcceleration = false } = await getAppConfig() + if (disableHardwareAcceleration) { + app.disableHardwareAcceleration() + } + } catch (e) { + console.warn('Failed to read hardware acceleration config:', e) + } +} + +initHardwareAcceleration() + // This method will be called when Electron has finished // initialization and is ready to create browser windows. // Some APIs can only be used after this event occurs. diff --git a/src/main/utils/template.ts b/src/main/utils/template.ts index b05c87b..57312ec 100644 --- a/src/main/utils/template.ts +++ b/src/main/utils/template.ts @@ -22,6 +22,7 @@ export const defaultConfig: IAppConfig = { controlDns: true, controlSniff: true, floatingWindowCompatMode: true, + disableHardwareAcceleration: false, disableLoopbackDetector: false, disableEmbedCA: false, disableSystemCA: false, diff --git a/src/renderer/src/components/settings/general-config.tsx b/src/renderer/src/components/settings/general-config.tsx index feb87be..6628779 100644 --- a/src/renderer/src/components/settings/general-config.tsx +++ b/src/renderer/src/components/settings/general-config.tsx @@ -30,6 +30,7 @@ import { IoIosHelpCircle, IoMdCloudDownload } from 'react-icons/io' import { MdEditDocument } from 'react-icons/md' import CSSEditorModal from './css-editor-modal' import { useTranslation } from 'react-i18next' +import BaseConfirmModal from '../base/base-confirm-modal' const GeneralConfig: React.FC = () => { const { t, i18n } = useTranslation() @@ -39,6 +40,8 @@ const GeneralConfig: React.FC = () => { const [openCSSEditor, setOpenCSSEditor] = useState(false) const [fetching, setFetching] = useState(false) const [isRelaunching, setIsRelaunching] = useState(false) + const [showHardwareAccelConfirm, setShowHardwareAccelConfirm] = useState(false) + const [pendingHardwareAccelValue, setPendingHardwareAccelValue] = useState(false) const { setTheme } = useTheme() const { silentStart = false, @@ -49,6 +52,7 @@ const GeneralConfig: React.FC = () => { showFloatingWindow: showFloating = false, spinFloatingIcon = true, floatingWindowCompatMode = true, + disableHardwareAcceleration = false, useWindowFrame = false, autoQuitWithoutCore = false, autoQuitWithoutCoreDelay = 60, @@ -78,6 +82,28 @@ const GeneralConfig: React.FC = () => { }} /> )} + {showHardwareAccelConfirm && ( + { + setShowHardwareAccelConfirm(false) + setPendingHardwareAccelValue(false) + }} + onConfirm={async () => { + setShowHardwareAccelConfirm(false) + setIsRelaunching(true) + try { + await patchAppConfig({ disableHardwareAcceleration: pendingHardwareAccelValue }) + await relaunchApp() + } catch (e) { + alert(e) + setIsRelaunching(false) + } + }} + /> + )}