#!/bin/bash

# Handle some arguments before running the application
# Supported arguments:
# -d|--debug: debug with -Wd arguments
PYDEBUG=false
PY='/usr/lib/iso-constructor/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.*iso-constructor$ &>/dev/null; then
    if $PYDEBUG; then
        mkdir -p "$HOME/.config/iso-constructor"
        env PYTHONVERBOSE=1 python3 -Wd "$PY" "$@" 2>&1 | tee "$HOME/.config/iso-constructor/iso-constructor-pydebug.log"
    else
        python3 "$PY" "$@"
    fi
fi
