diff --git a/scripts/setup-kiosk.sh b/scripts/setup-kiosk.sh index 47b5855..84ef13a 100755 --- a/scripts/setup-kiosk.sh +++ b/scripts/setup-kiosk.sh @@ -1,35 +1,72 @@ #!/bin/bash -# Configuration +set -e + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +PROJECT_DIR="$(dirname "$SCRIPT_DIR")" URL="http://localhost:3000" USER_NAME=$(whoami) AUTOSTART_DIR="/home/$USER_NAME/.config/autostart" -DESKTOP_FILE="$AUTOSTART_DIR/kiosk.desktop" +DESKTOP_FILE="$AUTOSTART_DIR/walldash-kiosk.desktop" +KIOSK_WRAPPER="$SCRIPT_DIR/start-kiosk.sh" + +# Ensure the wrapper is executable +chmod +x "$KIOSK_WRAPPER" + +# Install unclutter if missing (hides the mouse cursor) +if ! command -v unclutter &>/dev/null; then + echo "Installing unclutter..." + sudo apt-get install -y unclutter +fi + +# Install curl if missing (used by the wrapper to wait for the server) +if ! command -v curl &>/dev/null; then + echo "Installing curl..." + sudo apt-get install -y curl +fi # Create autostart directory if it doesn't exist mkdir -p "$AUTOSTART_DIR" -# Create the .desktop file for Chromium kiosk mode -cat < "$DESKTOP_FILE" +# Create the .desktop file pointing at our wrapper script +cat > "$DESKTOP_FILE" < /dev/null + done + # Disable screensaver if present + sudo sed -i 's/^@xscreensaver/# @xscreensaver/' "$LXDE_AUTOSTART" + echo "Updated $LXDE_AUTOSTART for screen blanking." fi -# Optional: Install unclutter to hide mouse cursor -# sudo apt-get update && sudo apt-get install -y unclutter -# echo "@unclutter -idle 0.1 -root" >> /etc/xdg/lxsession/LXDE-pi/autostart +# Disable screen blanking for Wayfire / Labwc (Pi OS Bookworm Wayland) +WAYFIRE_INI="$HOME/.config/wayfire.ini" +if [ -f "$WAYFIRE_INI" ]; then + if ! grep -q '\[idle\]' "$WAYFIRE_INI"; then + cat >> "$WAYFIRE_INI" <<'INI' -echo "Kiosk setup complete. Chromium will launch $URL on the next login." +[idle] +toggle = KEY_Z +screensaver_timeout = -1 +dpms_timeout = -1 +INI + echo "Disabled idle/screensaver in $WAYFIRE_INI." + fi +fi + +echo "" +echo "Kiosk setup complete." +echo "Chromium will open $URL automatically on the next login." +echo "To test now, run: $KIOSK_WRAPPER" diff --git a/scripts/setup-systemd.sh b/scripts/setup-systemd.sh index b623ab3..004e273 100755 --- a/scripts/setup-systemd.sh +++ b/scripts/setup-systemd.sh @@ -1,9 +1,12 @@ #!/bin/bash -# Configuration +set -e + SERVICE_NAME="walldash" USER_NAME=$(whoami) -DIR_PATH=$(pwd) +# Use the project directory relative to this script, not wherever the script is called from +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +PROJECT_DIR="$(dirname "$SCRIPT_DIR")" BUN_PATH=$(which bun) if [ -z "$BUN_PATH" ]; then @@ -14,16 +17,20 @@ fi # Create systemd service file cat </dev/null; then + CHROMIUM=chromium-browser +elif command -v chromium &>/dev/null; then + CHROMIUM=chromium +else + echo "ERROR: chromium / chromium-browser not found" >&2 + exit 1 +fi + +# Disable screen blanking / DPMS +xset s off +xset -dpms +xset s noblank + +# Hide mouse cursor (requires unclutter) +if command -v unclutter &>/dev/null; then + unclutter -idle 0.5 -root & +fi + +# Wait until the walldash server is accepting connections +echo "Waiting for $URL ..." +until curl -sf "$URL" -o /dev/null; do + sleep 2 +done +echo "Server ready." + +# Remove stale Chromium crash/exit flags so it doesn't show the "restore" prompt +CHROMIUM_PROFILE="$HOME/.config/chromium/Default" +if [ -f "$CHROMIUM_PROFILE/Preferences" ]; then + sed -i 's/"exit_type":"Crashed"/"exit_type":"Normal"/' "$CHROMIUM_PROFILE/Preferences" + sed -i 's/"exited_cleanly":false/"exited_cleanly":true/' "$CHROMIUM_PROFILE/Preferences" +fi + +# Run Chromium in a loop so a crash restarts it automatically +while true; do + $CHROMIUM \ + --noerrdialogs \ + --disable-infobars \ + --kiosk \ + --no-first-run \ + --disable-default-apps \ + --disable-component-update \ + --check-for-update-interval=31536000 \ + --disable-features=TranslateUI \ + --disable-pinch \ + --overscroll-history-navigation=0 \ + --autoplay-policy=no-user-gesture-required \ + "$URL" + echo "Chromium exited — restarting in 5 s..." + sleep 5 +done