#!/bin/sh
# Runs the Software Centre frontend that fits the running session: the Qt one (q4os-swcentre5)
# under Plasma and anything else that is not Trinity, the TDE one (q4os-swcentre) under Trinity -
# whichever of the two is installed when only one is. The Welcome screens and the menus launch the
# Software Centre through this, so a Plasma system never has to carry the TDE frontend for it.
# QDSK_SESSION is what the Q4OS session scripts export; print_session.sh derives it from the XDG
# variables when it is not set. (The same script as q4os-sw-profiler-common's desktop-profiler.)
if [ -z "$QDSK_SESSION" ] && [ -f /usr/share/apps/q4os_system/bin/print_session.sh ] ; then
  QDSK_SESSION="$( dash /usr/share/apps/q4os_system/bin/print_session.sh )"
fi
case "$QDSK_SESSION" in
  trinity) WANT="tde" ;;
  ""|unknown)
    # a Trinity session started by tdm carries none of the XDG session variables, but starttde
    # exports TDE_FULL_SESSION (Plasma exports KDE_FULL_SESSION, which stays on the Qt side)
    if [ -n "$TDE_FULL_SESSION" ] ; then WANT="tde" ; else WANT="qt" ; fi ;;
  *) WANT="qt" ;;
esac
if [ "$WANT" = "tde" ] ; then
  PREFER="/usr/bin/swcentre.exu" ; OTHER="/usr/bin/swcentre5.exu"
else
  PREFER="/usr/bin/swcentre5.exu" ; OTHER="/usr/bin/swcentre.exu"
fi
if [ -x "$PREFER" ] ; then
  exec "$PREFER" "$@"
elif [ -x "$OTHER" ] ; then
  exec "$OTHER" "$@"
fi
echo "software-centre: no Software Centre frontend installed (q4os-swcentre or q4os-swcentre5)" >&2
exit 127
