#!/bin/bash

# omarchy:summary=Remove the Epic Games Launcher and its settings, caches, and game Wine prefixes (with any saves kept only there).
# omarchy:requires-sudo=true

set -e

echo "Removing Epic Games Launcher..."

# Closing its window leaves the launcher running in the tray, where it would write its data back after the rm
launcher='^/usr/lib/epic-games-launcher/EpicGamesLauncher'
pkill -u "$USER" -f "$launcher" || true
for (( i = 0; i < 50; i++ )); do
  pgrep -u "$USER" -f "$launcher" >/dev/null || break
  sleep 0.2
done
pkill -KILL -u "$USER" -f "$launcher" || true

omarchy-pkg-drop epic-games-launcher-bin

rm -rf \
  "${XDG_DATA_HOME:-$HOME/.local/share}/com.epicgames.eglv2" \
  "${XDG_CACHE_HOME:-$HOME/.cache}/com.epicgames.eglv2" \
  "${XDG_CONFIG_HOME:-$HOME/.config}/autostart/epic-games-launcher.desktop" \
  "${XDG_CONFIG_HOME:-$HOME/.config}/autostart/eglv2.desktop"

echo ""
echo "The Epic Games Launcher, its settings, and each game's Wine prefix have been removed."
echo "Installed games stay where you put them (by default under ~/Games), but saves kept only in a prefix are gone."
echo "The sign-in token stays in your keyring until you delete it there."
