#!/bin/bash
# GR Processor — desinstalador
cd "$(dirname "$0")"

BIN_DIR="$HOME/.local/bin"
DESKTOP_DIR="$HOME/.local/share/applications"
ICON_DIR="$HOME/.local/share/icons/hicolor/256x256/apps"
CONFIG_DIR="$HOME/.config/gr-processor"

echo "==> Desinstalando GR Processor..."

# Detener proceso si está corriendo
if pgrep -x gr-processor &>/dev/null; then
    echo "==> Deteniendo gr-processor..."
    pkill -x gr-processor 2>/dev/null || true
    sleep 1
    pkill -9 -x gr-processor 2>/dev/null || true
fi

rm -f "$BIN_DIR/gr-processor"
rm -f "$DESKTOP_DIR/gr-processor.desktop"
rm -f "$ICON_DIR/gr-processor.png"
update-desktop-database "$DESKTOP_DIR" 2>/dev/null || true
gtk-update-icon-cache "$HOME/.local/share/icons/hicolor" 2>/dev/null || true

echo ""
echo "OK  GR Processor desinstalado."
echo ""
read -rp "¿Eliminar también la configuración en $CONFIG_DIR? [s/N] " resp
if [[ "$resp" =~ ^[sS]$ ]]; then
    rm -rf "$CONFIG_DIR"
    echo "==> Configuración eliminada."
else
    echo "==> Configuración conservada en $CONFIG_DIR"
fi
echo ""
