#!/bin/bash
# Wrapper to launch Big Remote Play Together

APP_DIR=""

# Detect installation directory
# Check Python site-packages (newest to oldest supported versions)
# Then fallback to /usr/share/big-remote-play-together
for i in /usr/lib/python3.{25..6}/site-packages/big-remote-play-together /usr/share/big-remote-play-together; do
    if [[ -d "$i" ]]; then
        APP_DIR="$i"
        break
    fi
done

# If not found, try local directory (development) relative to script
if [[ -z "$APP_DIR" ]]; then
    SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"
    APP_DIR="$SCRIPT_DIR/../share/big-remote-play-together"
fi

if [[ ! -f "$APP_DIR/main.py" ]]; then
    echo "Error: Application not found in $APP_DIR"
    exit 1
fi

# Execute main.py
exec python3 "$APP_DIR/main.py" "$@"
