improve handling of no hardware acceleration

This commit is contained in:
Vendicated
2025-06-08 21:21:57 +02:00
parent 48e9aea47e
commit fcb61c8f42
5 changed files with 29 additions and 6 deletions

View File

@@ -28,18 +28,23 @@ process.env.VENCORD_USER_DATA_DIR = DATA_DIR;
const isLinux = process.platform === "linux"; const isLinux = process.platform === "linux";
export let enableHardwareAcceleration = true;
function init() { function init() {
app.setAsDefaultProtocolClient("discord"); 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 enabledFeatures = new Set(app.commandLine.getSwitchValue("enable-features").split(","));
const disabledFeatures = new Set(app.commandLine.getSwitchValue("disable-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(); app.disableHardwareAcceleration();
} else { } else {
if (Settings.store.hardwareVideoAcceleration) { if (hardwareVideoAcceleration) {
enabledFeatures.add("AcceleratedVideoEncoder"); enabledFeatures.add("AcceleratedVideoEncoder");
enabledFeatures.add("AcceleratedVideoDecoder"); enabledFeatures.add("AcceleratedVideoDecoder");
@@ -85,8 +90,18 @@ function init() {
disabledFeatures.forEach(feat => enabledFeatures.delete(feat)); disabledFeatures.forEach(feat => enabledFeatures.delete(feat));
app.commandLine.appendSwitch("enable-features", [...enabledFeatures].filter(Boolean).join(",")); const enabledFeaturesArray = enabledFeatures.values().filter(Boolean).toArray();
app.commandLine.appendSwitch("disable-features", [...disabledFeatures].filter(Boolean).join(",")); 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 // 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"; if (isDeckGameMode) nativeTheme.themeSource = "dark";

View File

@@ -20,6 +20,7 @@ import {
} from "electron"; } from "electron";
import { mkdirSync, readFileSync, watch } from "fs"; import { mkdirSync, readFileSync, watch } from "fs";
import { open, readFile } from "fs/promises"; import { open, readFile } from "fs/promises";
import { enableHardwareAcceleration } from "main";
import { release } from "os"; import { release } from "os";
import { join } from "path"; import { join } from "path";
import { debounce } from "shared/utils/debounce"; 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_SETTINGS, () => Settings.plain);
handleSync(IpcEvents.GET_VERSION, () => app.getVersion()); handleSync(IpcEvents.GET_VERSION, () => app.getVersion());
handleSync(IpcEvents.GET_ENABLE_HARDWARE_ACCELERATION, () => enableHardwareAcceleration);
handleSync( handleSync(
IpcEvents.SUPPORTS_WINDOWS_TRANSPARENCY, IpcEvents.SUPPORTS_WINDOWS_TRANSPARENCY,

View File

@@ -25,7 +25,8 @@ export const VesktopNative = {
relaunch: () => invoke<void>(IpcEvents.RELAUNCH), relaunch: () => invoke<void>(IpcEvents.RELAUNCH),
getVersion: () => sendSync<void>(IpcEvents.GET_VERSION), getVersion: () => sendSync<void>(IpcEvents.GET_VERSION),
setBadgeCount: (count: number) => invoke<void>(IpcEvents.SET_BADGE_COUNT, count), setBadgeCount: (count: number) => invoke<void>(IpcEvents.SET_BADGE_COUNT, count),
supportsWindowsTransparency: () => sendSync<boolean>(IpcEvents.SUPPORTS_WINDOWS_TRANSPARENCY) supportsWindowsTransparency: () => sendSync<boolean>(IpcEvents.SUPPORTS_WINDOWS_TRANSPARENCY),
getEnableHardwareAcceleration: () => sendSync<boolean>(IpcEvents.GET_ENABLE_HARDWARE_ACCELERATION)
}, },
autostart: { autostart: {
isEnabled: () => sendSync<boolean>(IpcEvents.AUTOSTART_ENABLED), isEnabled: () => sendSync<boolean>(IpcEvents.AUTOSTART_ENABLED),

View File

@@ -21,6 +21,10 @@ addPatch({
// eslint-disable-next-line no-useless-escape // eslint-disable-next-line no-useless-escape
match: /(focus(\(\i\)){).{0,150}?\.focus\(\i,\i\)/, match: /(focus(\(\i\)){).{0,150}?\.focus\(\i,\i\)/,
replace: "$1VesktopNative.win.focus$2" replace: "$1VesktopNative.win.focus$2"
},
{
match: /,getEnableHardwareAcceleration/,
replace: "$&:VesktopNative.app.getEnableHardwareAcceleration,_oldGetEnableHardwareAcceleration"
} }
] ]
} }

View File

@@ -12,6 +12,7 @@ export const enum IpcEvents {
GET_VERSION = "VCD_GET_VERSION", GET_VERSION = "VCD_GET_VERSION",
SUPPORTS_WINDOWS_TRANSPARENCY = "VCD_SUPPORTS_WINDOWS_TRANSPARENCY", SUPPORTS_WINDOWS_TRANSPARENCY = "VCD_SUPPORTS_WINDOWS_TRANSPARENCY",
GET_ENABLE_HARDWARE_ACCELERATION = "VCD_GET_ENABLE_HARDWARE_ACCELERATION",
RELAUNCH = "VCD_RELAUNCH", RELAUNCH = "VCD_RELAUNCH",
CLOSE = "VCD_CLOSE", CLOSE = "VCD_CLOSE",