#!/usr/bin/env bash
# =============================================================================
#  DigitalWall - Raspberry Pi kiosk
#  Turns a Raspberry Pi into a dedicated DigitalWall screen: boots straight into
#  the player, full-screen, with the display kept awake.
#
#  Quick start (Raspberry Pi OS with desktop):
#    chmod +x digitalwall-rpi-kiosk.sh
#    ./digitalwall-rpi-kiosk.sh
#
#  Auto-start on boot — create ~/.config/autostart/digitalwall.desktop with:
#    [Desktop Entry]
#    Type=Application
#    Name=DigitalWall
#    Exec=/home/pi/digitalwall-rpi-kiosk.sh
#    X-GNOME-Autostart-enabled=true
#
#  On first run, pair the screen with the 6-character code it displays.
# =============================================================================
set -e
URL="https://app.digitalwall.in/player/"
export DISPLAY=:0

# Prevent the screen from blanking / sleeping
xset s off || true
xset -dpms || true
xset s noblank || true

# Hide the mouse cursor if 'unclutter' is installed (sudo apt install unclutter)
command -v unclutter >/dev/null 2>&1 && unclutter -idle 0.5 -root &

FLAGS="--kiosk --app=$URL --noerrdialogs --disable-infobars --disable-session-crashed-bubble --incognito --check-for-update-interval=31536000 --disable-features=Translate"

if command -v chromium-browser >/dev/null 2>&1; then
  exec chromium-browser $FLAGS
elif command -v chromium >/dev/null 2>&1; then
  exec chromium $FLAGS
else
  echo "Chromium not found. Install it:  sudo apt update && sudo apt install -y chromium-browser"
  exit 1
fi
