#!/usr/bin/env bash
# SPDX-License-Identifier: GPL-3.0-or-later
#
# pocketds-steam — system-installed entry point for the Steam launcher.
#
# Prefers the per-user $STEAMROOT/launch-steam.sh (because Switchdeck's
# script self-modifies and the user copy stays in step with whatever
# in-place tweaks the user makes) and falls back to the packaged copy
# under /usr/share/pocketds-steam/ if the per-user file is missing
# (e.g. user wiped $STEAMROOT to start over).

set -u

USER_LAUNCHER="${HOME}/.local/share/Steam/launch-steam.sh"
SYSTEM_LAUNCHER="/usr/share/pocketds-steam/launch-steam.sh"

# Kick the per-user bootstrap one more time if it hasn't run yet —
# covers the case where the user clicks the desktop launcher before
# the systemd --user oneshot fires (race on first login).
if [ ! -x "${USER_LAUNCHER}" ] && \
   command -v pocketds-steam-bootstrap >/dev/null 2>&1; then
    pocketds-steam-bootstrap || :
fi

if [ -x "${USER_LAUNCHER}" ]; then
    exec "${USER_LAUNCHER}" "$@"
fi
exec "${SYSTEM_LAUNCHER}" "$@"
