pub / sguard

Suspend Guard for the PhoneShell "Phosh"
git clone https://src.jayvii.de/pub/sguard.git
Home | Log | Files | Exports | Refs | README | RSS

commit f77def5fedb62b3cebac7d42af5fd78541a6d522
parent 021fa2d1a6606d3350451683bf06c66559a9824d
Author: JayVii <jayvii[AT]posteo[DOT]de>
Date:   Sat, 16 Jan 2021 16:48:30 +0100

Use mpris status

Diffstat:
Msguard/sguard.sh | 30++++++++++++++++++++++++------
1 file changed, 24 insertions(+), 6 deletions(-)

diff --git a/sguard/sguard.sh b/sguard/sguard.sh @@ -4,20 +4,38 @@ STATEFILE="/run/user/$UID/sguard.state" ORIGSTATE="/run/user/$UID/sguard.orig" TIMEOUT=60 -# supported applications -SUPPAPP="mpv gnome-podcasts lollypop rhythmbox" # Functions ------------------------------------------------------------------- -# check player state. FIXME: use mpris state via dbus instead of PIDs +# check player state. function check_player_state { - if [[ ! -z `pidof $1` ]]; then - echo true - else + PLAYERS=`list_services` + PL_STATUS="" + for pl in $PLAYERS; do + PL_STATUS="$PL_STATUS `get_status $pl`" + done + if [[ -z `echo $PL_STATUS | grep "Playing"` ]]; then echo false + else + echo true fi } +function get_status { # $1 - Player ("vlc", "mpv", ...) + gdbus call --session --dest $1 \ + --object-path /org/mpris/MediaPlayer2 \ + --method org.freedesktop.DBus.Properties.Get \ + org.mpris.MediaPlayer2.Player "PlaybackStatus" +} + +function list_services() { + # https://gist.github.com/amol9/6d47fdd21a1c5e006c84#file-vlc_dbus-sh-L35 + gdbus call --session --dest org.freedesktop.DBus \ + --object-path /org/freedesktop/DBus \ + --method org.freedesktop.DBus.ListNames \ + | grep -Po "'\w.*?'" | tr -d "'" | grep "org\.mpris\.MediaPlayer2" +} + # prevent sleep (and backup original state) function prevent_sleep { # take note of original settings