#!/bin/sh
# Check if NVIDIA proprietary driver is active
IS_NVIDIA=0
if [ -e /dev/nvidia0 ] || [ -e /dev/nvidiactl ] || [ -d /proc/driver/nvidia ] || grep -qi nvidia /proc/modules 2>/dev/null; then
    IS_NVIDIA=1
fi

# On Linux Wayland with NVIDIA, Chromium's native Wayland backend crashes on EGL/GBM/DRM.
# For NVIDIA on Wayland: route to X11 (XWayland) which is 100% stable with full GPU acceleration.
# For Intel / AMD on Wayland: run native Wayland for true kiosk fullscreen.
EXTRA_FLAGS=""
if [ "$IS_NVIDIA" -eq 1 ]; then
    EXTRA_FLAGS="--ozone-platform=x11 --disable-gpu-sandbox"
elif [ -n "$WAYLAND_DISPLAY" ] || [ "$XDG_SESSION_TYPE" = "wayland" ]; then
    EXTRA_FLAGS="--ozone-platform=wayland --enable-features=UseOzonePlatform,WaylandWindowDecorations"
else
    EXTRA_FLAGS="--ozone-platform=x11"
fi
exec /opt/Kodin/kodin --no-sandbox $EXTRA_FLAGS "$@"
