#!/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/--debug  and -i/--indicator
for arg in "$@"; do
    if [[ "$arg" == "-d" || "$arg" == "--debug" ]]; then
        PYDEBUG=true
    elif [[ "$arg" == "-i" || "$arg" == "--indicator" ]]; then
        systemctl start --user deb-software-indicator.service
        exit 0
    fi
done

# Check if GUI is already started
if ! pgrep -f python3.*/usr/lib/deb-software/main.py &>/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
