#!/bin/bash
set -euo pipefail

# Make the panel come from the package, every time.
#
# Plasma builds the panel from the classroom's layout script whenever it
# starts with no panel configuration, and keeps whatever it built after
# that. That means an update could change the bar in the package and
# never change it in a room — which is exactly what happened with an icon
# that outlived the file it came from.
#
# So the configuration is removed before the shell starts and the bar is
# rebuilt from the layout at every login. The desktop becomes stateless:
# there is nothing in a teacher's home that an update cannot reach, and a
# panel damaged somehow is repaired by the next login rather than by a
# technician.
#
# Nothing is lost by this. The panel is immutable to teachers by Kiosk
# policy, so there is never anything of theirs in that file.

CONFIG="${XDG_CONFIG_HOME:-$HOME/.config}/plasma-org.kde.plasma.desktop-appletsrc"

if [[ -e "$CONFIG" ]]; then
    rm -f "$CONFIG"
    echo "classroom-desktop-reset: panel will be rebuilt from the layout"
else
    echo "classroom-desktop-reset: no panel configuration to clear"
fi

# The icon cache remembers a name it once failed to find, which outlives
# the package that later supplies it.
rm -f "${XDG_CACHE_HOME:-$HOME/.cache}/icon-cache.kcache" 2>/dev/null || true
