#!/usr/bin/env bash
# Makes Superscribe Omarchy's dictation backend. Omarchy runs it for `omarchy default dictation superscribe`, in a
# terminal, as it runs its own omarchy-install-dictation-* scripts. Superscribe is already installed (this script
# comes with it), so this opens it, selects it (omarchy-dictation-use stops the previous backend and saves the
# choice) and reloads Hyprland so Alt+Space and Right Alt are bound to it.
set -e

if ! command -v omarchy-dictation-use >/dev/null 2>&1; then
    echo 'This is for Omarchy: omarchy-dictation-use was not found.' >&2
    exit 1
fi
if ! pgrep -u "$(id -u)" -x '[Ss]uperscribe' >/dev/null 2>&1; then
    setsid -f superscribe >/dev/null 2>&1 < /dev/null
fi
omarchy-dictation-use superscribe
if command -v omarchy-restart-hyprctl >/dev/null 2>&1; then omarchy-restart-hyprctl; fi
echo 'Superscribe is your dictation backend. Hold Right Alt, or press Alt+Space, to dictate. Keep Superscribe running.'
if command -v omarchy-notification-send >/dev/null 2>&1; then
    omarchy-notification-send -g 'Superscribe dictation is ready' 'Hold Right Alt, or press Alt+Space, to dictate.' -t 10000 || true
fi
