#!/bin/bash

# Handle some arguments before running the application
# Supported arguments:
# -d|--debug: debug with -Wd arguments
PYDEBUG=false
PY='/usr/lib/deb-software/main.py'

# Handle -d and --debug
for arg in "$@"; do
    if [[ "$arg" == "-d" || "$arg" == "--debug" ]]; then
        PYDEBUG=true
    fi
done

# Check if GUI is already started
if ! pgrep -f python3.*deb-software$ &>/dev/null; then
    if $PYDEBUG; then
        mkdir -p "$HOME/.config/deb-software"
        env PYTHONVERBOSE=1 python3 -Wd "$PY" "$@" 2>&1 | tee "$HOME/.config/deb-software/deb-software-pydebug.log"
    else
        python3 "$PY" "$@"
    fi
fi
