#!/usr/bin/env sh
# Installs an application-menu entry for this portable BurnSim build.
#
# The portable zip has no installer - this script is the middle ground between "just run the
# binary" and a real .deb/.rpm/AppImage package (see docs/ROADMAP.md's Linux-packaging backlog
# item for those options). It writes an absolute-path .desktop file pointing at wherever you
# extracted this folder, so BurnSim shows up in your desktop environment's application menu with
# its icon. Run it from inside the extracted folder: ./install-desktop-entry.sh
#
# Re-run this after moving the extracted folder - the .desktop file's paths are absolute and
# won't follow it automatically. To remove the menu entry:
#   rm ~/.local/share/applications/burnsim.desktop
set -e

SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
DEST_DIR="$HOME/.local/share/applications"
mkdir -p "$DEST_DIR"

chmod +x "$SCRIPT_DIR/BurnSim"

sed -e "s#__EXEC_PATH__#$SCRIPT_DIR/BurnSim#" \
    -e "s#__ICON_PATH__#$SCRIPT_DIR/burnsim.png#" \
    "$SCRIPT_DIR/BurnSim.desktop.template" > "$DEST_DIR/burnsim.desktop"

chmod +x "$DEST_DIR/burnsim.desktop"

if command -v update-desktop-database >/dev/null 2>&1; then
    update-desktop-database "$DEST_DIR" 2>/dev/null || true
fi

echo "Installed menu entry: $DEST_DIR/burnsim.desktop"
echo "BurnSim should now appear in your desktop environment's application menu."
