Skip to content

Instantly share code, notes, and snippets.

@sheepymeh
Last active September 4, 2021 07:43
Show Gist options
  • Save sheepymeh/77d0176faa771493dc9992173fe1359b to your computer and use it in GitHub Desktop.
Save sheepymeh/77d0176faa771493dc9992173fe1359b to your computer and use it in GitHub Desktop.
pacman hook for electron on wayland

Electron 12 introduced early Wayland support behind the flags --enable-features=UseOzonePlatform --ozone-platform=wayland.

This gist adds these flags to the .desktop files of the selected Electron packages after every upgrade, so that they can be started from a launcher with Wayland enabled.

Will be deprecated after Electron eventually starts with Wayland by default without needing these flags.

Usage

  1. Copy electron-wayland.sh to /usr/local/sbin/electron-wayland.sh
  2. Add execution permissions to /usr/local/sbin/electron-wayland.sh (sudo chmod a+x /usr/local/sbin/electron-wayland.sh)
  3. Copy electron-wayland.hook to /etc/pacman.d/hooks/electron-wayland.hook
  4. Update electron-wayland.hook with the Electron packages you'd like to patch automatically

If you save electron-wayland.sh elsewhere, please update Exec in electron-wayland.hook correspondingly

_You may need to create the /etc/pacman.d/hooks/ folder first``

[Trigger]
Operation = Install
Operation = Upgrade
Type = Package
# List required packages here
# Target = package 1
# Target = package 2 etc.
[Action]
Description = Adding Wayland flags for Electron
When = PostTransaction
Exec = /usr/local/sbin/electron-wayland.sh
NeedsTargets
#!/bin/bash
read pkgname
if ! pacman -Qq "$pkgname" >/dev/null 2>&1; then
echo 'package not found'
exit 1
fi
SAVEIFS=$IFS
IFS=$'\n'
DESKTOP_FILES=($(pacman -Qql "$pkgname" | grep '\.desktop$'))
IFS=$SAVEIFS
for (( i=0; i<${#DESKTOP_FILES[@]}; i++ )); do
if ! grep -q ' --enable-features=UseOzonePlatform --ozone-platform=wayland ' "${DESKTOP_FILES[$i]}"; then
perl -i -pe 's/^Exec=(\S+?)[ \n]/Exec=$1 --enable-features=UseOzonePlatform --ozone-platform=wayland /' "${DESKTOP_FILES[$i]}"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment