[Unit]
Description=Chromium Fullscreen Kiosk (Cage + MageDok 7" display)
Documentation=https://github.com/saltytech/saltylab-firmware/wiki/Cage-Chromium-Kiosk
Documentation=https://github.com/saltytech/saltylab-firmware/issues/374
After=network.target display-target.service
Before=graphical.target
Wants=display-target.service

# Disable GNOME if running
Conflicts=gdm.service gnome-shell.target

[Service]
Type=simple
User=orin
Group=video

# Environment
Environment="WAYLAND_DISPLAY=wayland-0"
Environment="XDG_RUNTIME_DIR=/run/user/1000"
Environment="XDG_SESSION_TYPE=wayland"
Environment="QT_QPA_PLATFORM=wayland"
Environment="SALTYBOT_KIOSK_URL=http://localhost:3000"

# Pre-start checks
ExecStartPre=/usr/bin/install -d /run/user/1000
ExecStartPre=/usr/bin/chown orin:orin /run/user/1000
ExecStartPre=/usr/bin/chmod 700 /run/user/1000

# Verify MageDok display is available
ExecStartPre=/usr/bin/test -c /dev/magedok-touch || /bin/true

# Start Chromium kiosk via Cage
ExecStart=/opt/saltybot/scripts/chromium_kiosk.sh --url http://localhost:3000

# Restart on failure
Restart=on-failure
RestartSec=5s

# Resource limits (Cage + Chromium is lightweight)
MemoryMax=512M
CPUQuota=80%
CPUAffinity=0 1 2 3

# Logging
StandardOutput=journal
StandardError=journal
SyslogIdentifier=chromium-kiosk

[Install]
WantedBy=graphical.target
