#!/usr/bin/env bash

# omarchy:summary=True when this process can talk to a live Hyprland instance.
# omarchy:hidden=true

# Named gate for every hyprctl caller (BASED-219, BASED-311). hyprctl may
# sit on PATH on a sway or GNOME image that also has the omarchy package;
# HYPRLAND_INSTANCE_SIGNATURE is the session, not the binary. Recover it
# the way omarchy-restart-sway finds SWAYSOCK, so a caller over ssh still
# sees the desktop that is actually running. ls, not find -printf: these
# scripts are bash and the packaged find is GNU, but the shell tests run
# on the Mac too.
if [[ -z ${HYPRLAND_INSTANCE_SIGNATURE:-} ]]; then
  hypr_dir=$(ls -td "${XDG_RUNTIME_DIR:-/run/user/$UID}"/hypr/*/ 2>/dev/null | head -n1)
  [[ -n $hypr_dir ]] && export HYPRLAND_INSTANCE_SIGNATURE=$(basename "${hypr_dir%/}")
fi

[[ -n ${HYPRLAND_INSTANCE_SIGNATURE:-} ]]
