From fcb61c8f42e97f5ae33e2f7253235a7aeff6f80f Mon Sep 17 00:00:00 2001 From: Vendicated Date: Sun, 8 Jun 2025 21:21:57 +0200 Subject: [PATCH] improve handling of no hardware acceleration --- src/main/index.ts | 25 ++++++++++++++++++++----- src/main/ipc.ts | 2 ++ src/preload/VesktopNative.ts | 3 ++- src/renderer/patches/windowMethods.tsx | 4 ++++ src/shared/IpcEvents.ts | 1 + 5 files changed, 29 insertions(+), 6 deletions(-) diff --git a/src/main/index.ts b/src/main/index.ts index c8bd462..37fd471 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -28,18 +28,23 @@ process.env.VENCORD_USER_DATA_DIR = DATA_DIR; const isLinux = process.platform === "linux"; +export let enableHardwareAcceleration = true; + function init() { app.setAsDefaultProtocolClient("discord"); - const { disableSmoothScroll, hardwareAcceleration } = Settings.store; + const { disableSmoothScroll, hardwareAcceleration, hardwareVideoAcceleration } = Settings.store; const enabledFeatures = new Set(app.commandLine.getSwitchValue("enable-features").split(",")); const disabledFeatures = new Set(app.commandLine.getSwitchValue("disable-features").split(",")); + app.commandLine.removeSwitch("enable-features"); + app.commandLine.removeSwitch("disable-features"); - if (hardwareAcceleration === false) { + if (hardwareAcceleration === false || process.argv.includes("--disable-gpu")) { + enableHardwareAcceleration = false; app.disableHardwareAcceleration(); } else { - if (Settings.store.hardwareVideoAcceleration) { + if (hardwareVideoAcceleration) { enabledFeatures.add("AcceleratedVideoEncoder"); enabledFeatures.add("AcceleratedVideoDecoder"); @@ -85,8 +90,18 @@ function init() { disabledFeatures.forEach(feat => enabledFeatures.delete(feat)); - app.commandLine.appendSwitch("enable-features", [...enabledFeatures].filter(Boolean).join(",")); - app.commandLine.appendSwitch("disable-features", [...disabledFeatures].filter(Boolean).join(",")); + const enabledFeaturesArray = enabledFeatures.values().filter(Boolean).toArray(); + const disabledFeaturesArray = disabledFeatures.values().filter(Boolean).toArray(); + + if (enabledFeaturesArray.length) { + app.commandLine.appendSwitch("enable-features", enabledFeaturesArray.join(",")); + console.log("Enabled Chromium features:", enabledFeaturesArray.join(", ")); + } + + if (disabledFeaturesArray.length) { + app.commandLine.appendSwitch("disable-features", disabledFeaturesArray.join(",")); + console.log("Disabled Chromium features:", disabledFeaturesArray.join(", ")); + } // In the Flatpak on SteamOS the theme is detected as light, but SteamOS only has a dark mode, so we just override it if (isDeckGameMode) nativeTheme.themeSource = "dark"; diff --git a/src/main/ipc.ts b/src/main/ipc.ts index fa0fe33..94eb671 100644 --- a/src/main/ipc.ts +++ b/src/main/ipc.ts @@ -20,6 +20,7 @@ import { } from "electron"; import { mkdirSync, readFileSync, watch } from "fs"; import { open, readFile } from "fs/promises"; +import { enableHardwareAcceleration } from "main"; import { release } from "os"; import { join } from "path"; import { debounce } from "shared/utils/debounce"; @@ -45,6 +46,7 @@ handleSync(IpcEvents.GET_RENDERER_CSS_FILE, () => join(__dirname, "renderer.css" handleSync(IpcEvents.GET_SETTINGS, () => Settings.plain); handleSync(IpcEvents.GET_VERSION, () => app.getVersion()); +handleSync(IpcEvents.GET_ENABLE_HARDWARE_ACCELERATION, () => enableHardwareAcceleration); handleSync( IpcEvents.SUPPORTS_WINDOWS_TRANSPARENCY, diff --git a/src/preload/VesktopNative.ts b/src/preload/VesktopNative.ts index ec993c1..8aee1e7 100644 --- a/src/preload/VesktopNative.ts +++ b/src/preload/VesktopNative.ts @@ -25,7 +25,8 @@ export const VesktopNative = { relaunch: () => invoke(IpcEvents.RELAUNCH), getVersion: () => sendSync(IpcEvents.GET_VERSION), setBadgeCount: (count: number) => invoke(IpcEvents.SET_BADGE_COUNT, count), - supportsWindowsTransparency: () => sendSync(IpcEvents.SUPPORTS_WINDOWS_TRANSPARENCY) + supportsWindowsTransparency: () => sendSync(IpcEvents.SUPPORTS_WINDOWS_TRANSPARENCY), + getEnableHardwareAcceleration: () => sendSync(IpcEvents.GET_ENABLE_HARDWARE_ACCELERATION) }, autostart: { isEnabled: () => sendSync(IpcEvents.AUTOSTART_ENABLED), diff --git a/src/renderer/patches/windowMethods.tsx b/src/renderer/patches/windowMethods.tsx index f58996f..5d67934 100644 --- a/src/renderer/patches/windowMethods.tsx +++ b/src/renderer/patches/windowMethods.tsx @@ -21,6 +21,10 @@ addPatch({ // eslint-disable-next-line no-useless-escape match: /(focus(\(\i\)){).{0,150}?\.focus\(\i,\i\)/, replace: "$1VesktopNative.win.focus$2" + }, + { + match: /,getEnableHardwareAcceleration/, + replace: "$&:VesktopNative.app.getEnableHardwareAcceleration,_oldGetEnableHardwareAcceleration" } ] } diff --git a/src/shared/IpcEvents.ts b/src/shared/IpcEvents.ts index e2da5db..faae369 100644 --- a/src/shared/IpcEvents.ts +++ b/src/shared/IpcEvents.ts @@ -12,6 +12,7 @@ export const enum IpcEvents { GET_VERSION = "VCD_GET_VERSION", SUPPORTS_WINDOWS_TRANSPARENCY = "VCD_SUPPORTS_WINDOWS_TRANSPARENCY", + GET_ENABLE_HARDWARE_ACCELERATION = "VCD_GET_ENABLE_HARDWARE_ACCELERATION", RELAUNCH = "VCD_RELAUNCH", CLOSE = "VCD_CLOSE",