#!/bin/bash
set -e

if [ "$1" = "remove" ] || [ "$1" = "purge" ]; then
    # Icon explizit löschen (falls dpkg es nicht entfernt)
    rm -f /usr/share/icons/hicolor/scalable/apps/io.github.nicolettas-muggelbude.myapps.svg || true

    # Leere Icon-Verzeichnisse aufräumen
    rmdir --ignore-fail-on-non-empty /usr/share/icons/hicolor/scalable/apps 2>/dev/null || true
    rmdir --ignore-fail-on-non-empty /usr/share/icons/hicolor/scalable 2>/dev/null || true

    # Icon-Cache aktualisieren
    if command -v gtk-update-icon-cache >/dev/null 2>&1; then
        gtk-update-icon-cache -f -t /usr/share/icons/hicolor || true
    fi

    # Desktop-Database aktualisieren
    if command -v update-desktop-database >/dev/null 2>&1; then
        update-desktop-database -q /usr/share/applications || true
    fi
fi

exit 0
