pmaports/main/postmarketos-artwork/set-plasma-wallpaper.sh
Oliver Smith 0059607677
main/postmarketos-artwork: set plasma wallpaper (MR 5186)
Set the postmarketOS wallpaper as default for Plasma Mobile and Plasma
Desktop, so we can change it across all UIs with every postmarketOS
release.

It would be nice if we could just set the wallpaper with a simple config
file (reported https://bugs.kde.org/show_bug.cgi?id=487816). Until that
is possible, use a shell script as workaround.

Copy the contents dir and metadata.json file explicitly, instead of
copying the entire "meadow" directory. With this change we avoid copying
meadow.svg, which fixes two issues:
* This file doesn't have a stable name, when we switch to the next
  wallpaper and the user had selected it, the wallpaper will just be
  gone instead of automatically switching to the new wallpaper.
* It shows up as broken wallpaper in Plasma's wallpaper selection.

[ci:skip-build]: already built successfully in CI
2024-06-02 19:37:43 +02:00

38 lines
1 KiB
Bash

#!/bin/sh
# Set the postmarketOS wallpaper in Plasma based UIs. Replace this hack when we
# have a cleaner method: https://bugs.kde.org/show_bug.cgi?id=487816
MARKER=~/.local/state/postmarketos/plasma-wallpaper-has-been-set
WALLPAPER_PATH="/usr/share/wallpapers/postmarketos"
# Only run this script in Plasma sessions. This variable is set in in both
# Plasma Desktop and Plasma Mobile (unlike e.g. XDG_DESKTOP_SESSION).
if [ -z "$KDE_FULL_SESSION" ]; then
exit 1
fi
# Only run this script once. If the user selects a different wallpaper
# afterwards, it should not be changed.
if [ -e "$MARKER" ]; then
exit 0
fi
echo "set-plasma-wallpaper: changing to: $WALLPAPER_PATH"
# Unfortunately this fails if the D-Bus API isn't available yet. So we have to
# try multiple times.
for i in $(seq 1 30); do
sleep 1
if ! plasma-apply-wallpaperimage "$WALLPAPER_PATH"; then
continue
fi
mkdir -p "$(dirname "$MARKER")"
touch "$MARKER"
echo "set-plasma-wallpaper: success"
exit 0
done
echo "set-plasma-wallpaper: failed"
exit 1