#!/bin/sh
# desktop-reboot — cross-DE reboot

DESKTOP="${XDG_CURRENT_DESKTOP:-$DESKTOP_SESSION:-}"
DESKTOP_LOWER="$(printf '%s' "$DESKTOP" | tr '[:upper:]' '[:lower:]')"

case "$DESKTOP_LOWER" in
  *gnome*|*ubuntu*)
    if command -v gnome-session-quit >/dev/null 2>&1; then
      exec gnome-session-quit --reboot --force
    fi
    exec systemctl reboot
    ;;
  *xfce*|*xubuntu*)
    if command -v xfce4-session-logout >/dev/null 2>&1; then
      exec xfce4-session-logout --reboot --fast
    fi
    exec systemctl reboot
    ;;
  *budgie*|*ubuntu-budgie*)
    if command -v gnome-session-quit >/dev/null 2>&1; then
      exec gnome-session-quit --reboot --force
    fi
    exec systemctl reboot
    ;;
  *)
    if command -v gnome-session-quit >/dev/null 2>&1; then
      exec gnome-session-quit --reboot --force
    fi
    if command -v xfce4-session-logout >/dev/null 2>&1; then
      exec xfce4-session-logout --reboot --fast
    fi
    exec systemctl reboot
    ;;
esac
