arch-packages/discord-launcher.sh
Zoddo 0338eedbf5
upgpkg: discord 0.0.112-4: fix wayland detection
There is a false positive on non-wayland systems because the socket extistance
test end up checking whether XDG_RUNTIME_DIR exists (which is always true)
2025-10-17 21:30:02 +02:00

44 lines
1.4 KiB
Bash

#!/usr/bin/env bash
set -euo pipefail
name=@PKGNAME@
ver=@PKGVER@
electron=@ELECTRON@
declare -a flags
declare -l PATCH_KRISP
[[ -r "${XDG_CONFIG_HOME:-$HOME/.config}/${name}.conf" ]] && source "${XDG_CONFIG_HOME:-$HOME/.config}/${name}.conf"
flags_file="${XDG_CONFIG_HOME:-$HOME/.config}/${name}-flags.conf"
krisp_bin="${DISCORD_USER_DATA_DIR:-${XDG_CONFIG_HOME:-$HOME/.config}/${name}}/${ver}/modules/${name}_krisp/${name}_krisp.node"
if [[ "${PATCH_KRISP:-}" == true ]] && [[ -w "${krisp_bin}" ]]; then
if hash python &> /dev/null && python -c 'import capstone; import elftools' &> /dev/null; then
# Patch Krisp binary to ignore signature check
echo -n 'Running Krisp patcher... '
python /usr/share/${name}/krisp-patcher.py "${krisp_bin}"
fi
fi
if [[ -r "${flags_file}" ]]; then
mapfile -t < "${flags_file}"
fi
for line in "${MAPFILE[@]}"; do
if [[ ! "${line}" =~ ^[[:space:]]*#.* ]] && [[ -n "${line}" ]]; then
flags+=("${line}")
fi
done
if [[ -S "${XDG_RUNTIME_DIR:-}/${WAYLAND_SOCKET:-}" || -e "${WAYLAND_DISPLAY:-}" || "${XDG_SESSION_TYPE:-}" == "wayland" ]]; then
# work around electron's broken wayland detection
# TODO: remove when Arch updates to an electron release that includes the fix
# https://github.com/electron/electron/pull/48301
flags+=("--ozone-platform=wayland")
fi
exec /usr/bin/${electron} \
/usr/share/${name}/resources/app.asar \
"${flags[@]}" "$@"