diff --git a/dot_local/bin/executable_discord-launch b/dot_local/bin/executable_discord-launch new file mode 100644 index 0000000..27f8357 --- /dev/null +++ b/dot_local/bin/executable_discord-launch @@ -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 "$@" diff --git a/dot_local/scripts/discord/executable_va-api-hevc-patch.sh b/dot_local/scripts/discord/executable_va-api-hevc-patch.sh new file mode 100644 index 0000000..f552642 --- /dev/null +++ b/dot_local/scripts/discord/executable_va-api-hevc-patch.sh @@ -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 diff --git a/dot_local/share/applications/discord.desktop b/dot_local/share/applications/discord.desktop.tmpl similarity index 55% rename from dot_local/share/applications/discord.desktop rename to dot_local/share/applications/discord.desktop.tmpl index 3bdbe7b..807dd41 100644 --- a/dot_local/share/applications/discord.desktop +++ b/dot_local/share/applications/discord.desktop.tmpl @@ -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;