#! /usr/bin/env bash

# make sure errors in sourced scripts will cause this script to stop
set -e

this_dir="$(readlink -f "$(dirname "$0")")"

PAGEEDIT_EXTRA_ROOT="$this_dir/usr/share/pageedit"
export PAGEEDIT_EXTRA_ROOT
echo "${PAGEEDIT_EXTRA_ROOT}"

# LD_LIBRARY_PATH="$this_dir/usr/lib:$LD_LIBRARY_PATH"
# export LD_LIBRARY_PATH
# echo "$LD_LIBRARY_PATH"

# Incorporate old qt-hook script contents here since the auto-hook generation stopped upstream
case "${XDG_CURRENT_DESKTOP}" in
    *GNOME*|*gnome*|*XFCE*)
        export QT_QPA_PLATFORMTHEME=gtk3
        ;;
esac

# Call the pageedit binary directly since AppRun.wrapped is no longer auto-generated
LD_LIBRARY_PATH="$this_dir/usr/lib:$LD_LIBRARY_PATH" exec "$this_dir"/usr/bin/pageedit "$@"
