Skip to content

Instantly share code, notes, and snippets.

@ItsProfessional
Last active June 2, 2023 07:06
Show Gist options
  • Save ItsProfessional/b8e581301449120f97cb3aa61581e282 to your computer and use it in GitHub Desktop.
Save ItsProfessional/b8e581301449120f97cb3aa61581e282 to your computer and use it in GitHub Desktop.
Pacman hooks for auto repatching discord without manual intervention (system electron, vencord, openasar)
#!/bin/sh
# Extract asar and rename original file
asar e /opt/discord/resources/app.asar /opt/discord/resources/app
mv /opt/discord/resources/app.asar /opt/discord/resources/app.asar.default -f
# Patch extracted asar
sed -i "s|process.resourcesPath|'/usr/share/discord/resources'|" /opt/discord/resources/app/app_bootstrap/buildInfo.js
sed -i "s|exeDir,|'/usr/share/pixmaps',|" /opt/discord/resources/app/app_bootstrap/autoStart/linux.js
sed -i "s|module.paths = \[\]|module.paths = \[process.env.HOME + '/.config/discordcanary/$pkgver/modules'\]|" /opt/discord/resources/app/app_bootstrap/requireNative.js
# Repack asar
asar p /opt/discord/resources/app /opt/discord/resources/app.asar
rm -rf /opt/discord/resources/app
# Replace the Discord binary with a shell script that uses the system electron
mv /opt/discord/Discord /opt/discord/Discord.bak
cat <<EOT > /opt/discord/Discord
#!/bin/sh
if [ "$XDG_SESSION_TYPE" = wayland ]; then
# Using wayland
exec electron24 \\
--enable-features=UseOzonePlatform \\
--ozone-platform=wayland \\
--enable-accelerated-mjpeg-decode \\
--enable-accelerated-video \\
--ignore-gpu-blacklist \\
--enable-native-gpu-memory-buffers \\
--enable-gpu-rasterization \\
--enable-gpu \\
--enable-features=WebRTCPipeWireCapturer \\
--enable-blink-features=MiddleClickAutoscroll \\
/opt/discord/resources/app.asar $@
else
# Using x11
exec electron24 \\
--enable-accelerated-mjpeg-decode \\
--enable-accelerated-video \\
--ignore-gpu-blacklist \\
--enable-native-gpu-memory-buffers \\
--enable-gpu-rasterization \\
--enable-gpu \\
--enable-blink-features=MiddleClickAutoscroll \\
/opt/discord/resources/app.asar $@
fi
EOT
chmod 755 /opt/discord/Discord
# Install vencord and openasar
clipath=/tmp/$(mktemp -u vencord-cli-XXXXXXXX)
# Download vencord cli
curl -s https://api.github.com/repos/Vencord/Installer/releases/latest \
| jq -r ".assets[] | .browser_download_url" \
| grep ".*VencordInstallerCli-linux" \
| wget -O "$clipath" -qi -
chmod a+x "$clipath"
eval "$clipath --branch stable --install-openasar"
eval "$clipath --branch stable --install"
rm -rf "$clipath"
[Trigger]
Type = Package
Operation = Install
Operation = Upgrade
Target = discord
[Action]
Description = Patching discord (system electron, openasar, vencord)
When = PostTransaction
Exec = /home/proferk/scripts/pacman-hooks/patch-discord.sh
Depends = asar
[Trigger]
Type = Package
Operation = Remove
Operation = Upgrade
Target = discord
[Action]
Description = Removing discord patches (system electron, openasar, vencord)
When = PreTransaction
Exec = /home/proferk/scripts/pacman-hooks/unpatch-discord.sh
#!/bin/sh
if [ -e "/opt/discord/Discord.bak" ]; then
rm -rf /opt/discord/Discord
mv -f /opt/discord/Discord.bak /opt/discord/Discord
fi
if [ -e "/opt/discord/resources/app.asar.default" ]; then
rm -rf /opt/discord/resources/app.asar
rm -rf /opt/discord/resources/_app.asar
rm -rf /opt/discord/resources/app.asar.original
mv -f /opt/discord/resources/app.asar.default /opt/discord/resources/app.asar
elif [ -d "/opt/discord/resources/app.asar" ]; then
# app.asar is a directory i.e. vencord is installed
rm -rf /opt/discord/resources/app.asar
if [ -e "/opt/discord/resources/app.asar.original" ]; then
# openasar is also installed
rm -rf /opt/discord/resources/_app.asar
mv -f /opt/discord/resources/app.asar.original /opt/discord/resources/app.asar
else
# only vencord is installed
mv -f /opt/discord/resources/_app.asar /opt/discord/resources/app.asar
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment