#!/usr/bin/env bash
# Lock the session with the forgeOS lock screen (Quickshell). Run by Super+L
# and by hypridle. If the lock screen fails to start or exits with an error,
# fall back to hyprlock so the session is never left unlocked.
set -u

pidof hyprlock >/dev/null && exit 0

# --no-duplicate: a second lock request while locked exits 0 at once.
quickshell --no-duplicate --path /usr/share/forgeos/quickshell/lock.qml
status=$?
if (( status != 0 )); then
	logger -t forgeos-lock "forgeOS lock screen exited with status $status; starting hyprlock"
	exec hyprlock
fi
