#!/bin/bash
# Start a CyloneOS static web UI (files, settings, …) in application mode.
set -euo pipefail

APP="${1:?usage: cyloneos-webapp <app-id>}"
ROOT="/usr/share/cyloneos/${APP}"
INDEX="${ROOT}/index.html"

if [ ! -f "${INDEX}" ]; then
	echo "cyloneos-webapp: '${APP}' nicht installiert (${INDEX} fehlt)." >&2
	exit 1
fi

URL="file://${INDEX}"

if command -v epiphany-browser >/dev/null 2>&1; then
	PROFILE="${XDG_CACHE_HOME:-$HOME/.cache}/cyloneos-epiphany-${APP}"
	exec epiphany-browser --profile="${PROFILE}" --application-mode "${URL}"
fi

if command -v chromium >/dev/null 2>&1; then
	exec chromium --app="${URL}"
fi

if command -v google-chrome >/dev/null 2>&1; then
	exec google-chrome --app="${URL}"
fi

exec xdg-open "${URL}"
