#!/bin/bash
# Fedorium — apply a theme variant to the current user's Plasma session.
# Usage: fedorium-apply-theme blue|purple
#   blue   = default Fedorium (wallpaper + launcher icon)
#   purple = Fedorium Coding
# Both stay changeable afterwards: right-click desktop -> Desktop and Wallpaper,
# right-click the launcher -> Configure Application Launcher -> icon.

case "$1" in
    purple) WP=/usr/share/wallpapers/FedoriumCoding/contents/images/3840x2160.png; ICON=fedorium-logo-coding ;;
    *)      WP=/usr/share/wallpapers/Fedorium/contents/images/3840x2160.png;       ICON=fedorium-logo ;;
esac

# wait for Plasma
for _ in $(seq 1 60); do
    dbus-send --session --print-reply --dest=org.kde.plasmashell /PlasmaShell \
        org.freedesktop.DBus.Peer.Ping >/dev/null 2>&1 && break
    sleep 1
done

plasma-apply-wallpaperimage "$WP" >/dev/null 2>&1

JS='panels().forEach(function(p){p.widgets().forEach(function(w){
if(w.type=="org.kde.plasma.kickoff"||w.type=="org.kde.plasma.kicker"||w.type=="org.kde.plasma.kickerdash"){
w.currentConfigGroup=["General"];w.writeConfig("icon","'"$ICON"'");w.reloadConfig();}})})'
dbus-send --session --type=method_call --dest=org.kde.plasmashell /PlasmaShell \
    org.kde.PlasmaShell.evaluateScript string:"$JS" >/dev/null 2>&1

kwriteconfig6 --file kscreenlockerrc --group Greeter --group Wallpaper --group org.kde.image \
    --group General --key Image "file://$WP" 2>/dev/null
exit 0
