#!/bin/bash
set -e
DEFAULT_CONFIG="$HOME/.config/iuve-connect-agent/desktop-config.json"
AGENT_ROOT="/opt/iuve-connect-desktop-agent"
export PYTHONPATH="$AGENT_ROOT/vendor:$AGENT_ROOT:${PYTHONPATH:-}"

if [ "$#" -gt 0 ] && { [ "$1" = "tray" ] || [ "$1" = "run" ] || [ "$1" = "status" ] || [ "$1" = "console" ] || [ "$1" = "ui" ]; }; then
  has_config=0
  for arg in "$@"; do
    if [ "$arg" = "--config" ]; then
      has_config=1
      break
    fi
  done
  if [ "$has_config" -eq 0 ]; then
    exec -a iuve-connect-agent /usr/bin/python3 -m iuve_connect_agents.desktop.app "$@" --config "$DEFAULT_CONFIG"
  fi
fi

exec -a iuve-connect-agent /usr/bin/python3 -m iuve_connect_agents.desktop.app "$@"
