[.desktop] Add discord patch for VA-API and HVEC

This commit is contained in:
aloslider committed 2026-11-20 01:48:19 +03:00
1 parent 26a2d80707
commit 1b7517ee21
3 files changed
+34 -1

No files matched your search

+4
View File
@@ -0,0 +1,4 @@
#!/bin/sh
discord-patch || echo "discord-patch failed, launching unpatched" >&2
exec env LIBVA_DRIVER_NAME=nvidia NVD_BACKEND=direct /usr/bin/discord \
--ozone-platform=wayland --use-gl=angle --disable-gpu-sandbox "$@"
@@ -0,0 +1,29 @@
#!/bin/sh
set -eu
name="va-api-hevc-patch"
base="${XDG_CONFIG_HOME:-$HOME/.config}/discord"
marker="VaapiOnNvidiaGPUs"
for asar in "$base"/app-*/resources/app.asar; do
[ -f "$asar" ] || continue
grep -q "$marker" "$asar" && continue
echo "$name: patching $asar"
work=$(mktemp -d)
npx --yes @electron/asar extract "$asar" "$work"
perl -0pi -e 's/\Qapp.commandLine.appendSwitch("disable-features",disabledFeatures.join(","))\E/app.commandLine.appendSwitch("disable-features",[...disabledFeatures,"UseChromeOSDirectVideoDecoder"].join(","))/' "$work/bundle.js"
perl -0pi -e 's/\Qelectron.app.commandLine.appendSwitch("enable-features","DocumentPolicyIncludeJSCallStacksInCrashReports")\E/electron.app.commandLine.appendSwitch("enable-features","DocumentPolicyIncludeJSCallStacksInCrashReports,VaapiOnNvidiaGPUs,VaapiIgnoreDriverChecks,PlatformHEVCDecoderSupport,AcceleratedVideoDecodeLinuxGL")/' "$work/bundle.js"
if ! grep -q 'UseChromeOSDirectVideoDecoder' "$work/bundle.js" || ! grep -q "$marker" "$work/bundle.js"; then
echo "$name: patterns not found, leaving $asar untouched" >&2
command -v notify-send >/dev/null && notify-send "Discord patch failed" "Discord's code changed, update $name"
rm -rf "$work"
continue
fi
[ -f "$asar.bak" ] || cp "$asar" "$asar.bak"
npx --yes @electron/asar pack "$work" "$asar"
rm -rf "$work"
done
@@ -3,7 +3,7 @@ Name=Discord
StartupWMClass=discord
Comment=All-in-one voice and text chat for gamers that's free, secure, and works on both your desktop and phone.
GenericName=Internet Messenger
Exec=env LIBVA_DRIVER_NAME=nvidia NVD_BACKEND=direct /usr/bin/discord --ignore-gpu-blocklist --use-gl=angle --use-angle=gl --enable-features=WaylandWindowDecorations,AcceleratedVideoDecodeLinuxGL,VaapiOnNvidiaGPUs --ozone-platform-hint=auto --url -- %u
Exec={{ .chezmoi.homeDir }}/.local/bin/discord-launch --url -- %u
Icon=discord
Type=Application
Categories=Network;InstantMessaging;