#!/usr/bin/env sh
# PINAKA Chess — Linux Desktop Launcher
# Opens PINAKA in a dedicated chromeless desktop window using the installed browser.
set -eu

URL="https://pinakachess.com/app?mode=installed"

for bin in google-chrome-stable google-chrome chromium chromium-browser brave-browser microsoft-edge-stable microsoft-edge vivaldi-stable vivaldi; do
  if command -v "$bin" >/dev/null 2>&1; then
    exec "$bin" --app="$URL" --class=pinaka-chess "$@"
  fi
done

if command -v flatpak >/dev/null 2>&1; then
  for appid in com.google.Chrome org.chromium.Chromium com.brave.Browser com.microsoft.Edge; do
    if flatpak info "$appid" >/dev/null 2>&1; then
      exec flatpak run "$appid" --app="$URL" --class=pinaka-chess "$@"
    fi
  done
fi

if command -v xdg-open >/dev/null 2>&1; then
  exec xdg-open "$URL"
fi

echo "PINAKA Chess: install Chrome, Chromium, Brave, Edge, or Firefox and visit $URL" >&2
exit 1
