Files
sxmo-utils/scripts/core/sxmo_playerctl.sh
Maarten van Gompel 7841952fb1 sxmo_playerctl.sh: return should be exit
In scoprion2185's log I saw:

/usr/bin/sxmo_playerctl.sh: line 31: return: can only `return' from a function or sourced script

As far as I checked, sxmo_playerctl is indeed called normally rather
than sourced so it should be exit instead of return, this patch fixes
that.

Signed-off-by: Willow Barraco <contact@willowbarraco.fr>
2024-06-05 08:14:23 +02:00

42 lines
694 B
Bash
Executable File

#!/bin/sh
ROOT_DIR="$XDG_RUNTIME_DIR"/sxmo_playerctl
mkdir -p "$ROOT_DIR"
PAUSED_FILE="$ROOT_DIR"/paused
list_playing() {
playerctl -l | while read -r player; do
if playerctl -p "$player" status | grep -q Playing; then
printf "%s\n" "$player"
fi
done
}
pause_all() {
list_playing >> "$PAUSED_FILE"
xargs -P10 -I{} -n1 playerctl -p "{}" pause < "$PAUSED_FILE"
}
resume_all() {
[ ! -e "$PAUSED_FILE" ] && return
xargs -P10 -I{} -n1 playerctl -p "{}" play < "$PAUSED_FILE"
rm "$PAUSED_FILE"
}
if ! command -v playerctl >/dev/null; then
exit
fi
if ! playerctl status >/dev/null 2>&1; then
exit
fi
case "$1" in
pause_all)
pause_all
;;
resume_all)
resume_all
;;
esac