#!/bin/sh
# PhoneRC web installer — generated from phone-rc/shortcut-launcher.
# Do not edit here; edit the source in the phone-rc repository.
set -eu

INSTALL_DIR="${PHONERC_COMPANION_HOME:-$HOME/.local/share/phonerc-companion}"

case "$(uname -s)" in
  Darwin)
    AGENT_FILE="$HOME/Library/LaunchAgents/net.stoicsoft.phonerc-companion.plist"
    launchctl bootout "gui/$(id -u)" "$AGENT_FILE" >/dev/null 2>&1 || true
    rm -f "$AGENT_FILE"
    ;;
  Linux)
    if command -v systemctl >/dev/null 2>&1; then
      systemctl --user disable --now phonerc-companion.service >/dev/null 2>&1 || true
      rm -f "$HOME/.config/systemd/user/phonerc-companion.service"
      systemctl --user daemon-reload >/dev/null 2>&1 || true
    fi
    rm -f "$HOME/.config/autostart/phonerc-companion.desktop"
    # Best-effort stop of any stray listener started outside a service.
    pkill -f "$INSTALL_DIR/shortcut_launcher.py" >/dev/null 2>&1 || true
    ;;
  *)
    echo "This uninstaller supports macOS and Linux." >&2
    exit 1
    ;;
esac

rm -rf "$INSTALL_DIR"
echo "PhoneRC Companion uninstalled."
