#!/bin/sh
SCRIPTPATH="$(dirname "$(readlink -f "$0")")"

# If you want to use a custom Qt installation:
# (please note that this will be reverted at every update)
#export LD_LIBRARY_PATH="/opt/Qt/5.10/gcc_64/lib:${LD_LIBRARY_PATH}"

# In Ubuntu Unity, appmenu-qt5 will try to hide our menubar in order to show it as a global bar. 
# This may sometimes fail and leave us with no menu bar. So we'll prevent appmenu-qt5 for doing this.
if [ "$QT_QPA_PLATFORMTHEME" = "appmenu-qt5" ]; then
    export QT_QPA_PLATFORMTHEME=""
fi

# For less common desktop environments, this doesn't get set at all which will cause QT to default to
# using KDE's icon theme settings and cause a lot of missing icon errors.  Most enviornments that don't
# set this preference GTK's settings... so go with that by default.
if [ -z "$XDG_CURRENT_DESKTOP" ]; then
    export XDG_CURRENT_DESKTOP="GNOME"
fi

if [ -f "$SCRIPTPATH"/../lib/notepadqq/notepadqq-bin ]; then
    # Nqq is installed: this script is in bin/
    exec "$SCRIPTPATH"/../lib/notepadqq/notepadqq-bin "$@"
elif [ -f "$SCRIPTPATH"/../lib/notepadqq-bin ]; then
    # Nqq is not installed: this script is in bin/
    exec "$SCRIPTPATH"/../lib/notepadqq-bin "$@"
elif [ -f "$SCRIPTPATH"/../../usr/libexec/notepadqq/notepadqq-bin ]; then
    # Nqq installed via rpm package (Fedora):
    # Script is installed in /usr/libexec/notepadqq folder for comply with FHS and run without changing much
    exec "$SCRIPTPATH"/../../usr/libexec/notepadqq/notepadqq-bin "$@"
else
    # Nqq is installed via deb package:
    # this script is in the same directory as the binary file.
    exec "$SCRIPTPATH"/notepadqq-bin "$@"
fi
