Skip to content

Commit

Permalink
⚡️ perf: extension wayland handling
Browse files Browse the repository at this point in the history
  • Loading branch information
d3v1l0n committed Dec 23, 2024
1 parent 19859b5 commit 0062c26
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions snigdhaos-libs/pkexec-gui
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,25 @@ if ! command -v pkexec &>/dev/null; then
fi

# Check if running as root
if [ $EUID -ne 0 ]; then
if [[ $EUID -ne 0 ]]; then
# Attempt to execute the script as root via pkexec
exec pkexec /usr/lib/snigdhaos/pkexec-gui "$@"
exit 1
fi

# Need some previous vars
# Shellcheck disable: Read environment variables from parent process
# shellcheck disable=SC2163
while IFS= read -rd '' var; do export "$var"; done < <(grep --null-data -ae "^\($XDG_CURRENT_DESKTOP\|WAYLAND_DISPLAY\|XDG_RUNTIME_DIR\|XDG_SESSION_TYPE\|XCURSOR_SIZE\|LC_*\|LANG\|LANGUAGE\|QT_WAYLAND_FORCE_DPI\|QT_QPA_PLATFORMTHEME\|QT_STYLE-OVERRIDE\|\)=.*\$" /proc/$PPID/environ)
# Read the necessary environment variables from the parent process
while IFS= read -rd '' var; do
export "$var"
done < <(grep --null-data -ae "^\($XDG_CURRENT_DESKTOP\|WAYLAND_DISPLAY\|XDG_RUNTIME_DIR\|XDG_SESSION_TYPE\|XCURSOR_SIZE\|LC_*\|LANG\|LANGUAGE\|QT_WAYLAND_FORCE_DPI\|QT_QPA_PLATFORMTHEME\|QT_STYLE-OVERRIDE\|\)=.*\$" /proc/$PPID/environ)

# If on Wayland, adjust WAYLAND_DISPLAY variable
if [[ -v WAYLAND_DISPLAY ]]; then
# Adjust WAYLAND_DISPLAY if running on Wayland
if [[ -n "$WAYLAND_DISPLAY" ]]; then
export WAYLAND_DISPLAY="$XDG_RUNTIME_DIR/$WAYLAND_DISPLAY"
fi

# Set root's runtime directory
# Set the root user's XDG_RUNTIME_DIR
export XDG_RUNTIME_DIR="/run/user/0"

# Execute the provided command with root privileges
Expand Down

0 comments on commit 0062c26

Please sign in to comment.