#!/bin/sh
set -e
export ETHERAGENTS_BROKER_PORT="${ETHERAGENTS_BROKER_PORT:-4018}"
node /usr/lib/etheragents-desktop/broker.mjs &
BROKER_PID=$!
trap 'kill "$BROKER_PID" 2>/dev/null || true' EXIT INT TERM
APP_URL="${ETHERAGENTS_APP_URL:-https://etherailabs.com/app}"
if command -v chromium >/dev/null; then
  chromium --app="$APP_URL"
elif command -v google-chrome >/dev/null; then
  google-chrome --app="$APP_URL"
elif command -v firefox >/dev/null; then
  firefox --new-window "$APP_URL"
else
  xdg-open "$APP_URL"
fi
wait "$BROKER_PID" || true
