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 6a760e006f099c493aa837a03972df9d0efa86d3
parent 3ef79905274b0f781d0bbc4626aaa8998f162165
Author: JayVii <jayvii[AT]posteo[DOT]de>
Date:   Mon, 11 Jan 2021 16:05:18 +0100

Cleanup

Diffstat:
Msguard/sguard.sh | 20++++++++++++++++----
1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/sguard/sguard.sh b/sguard/sguard.sh @@ -1,12 +1,14 @@ #!/usr/bin/env bash +# Configuration --------------------------------------------------------------- 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 function check_player_state { if [[ ! -z `pidof $1` ]]; then @@ -16,6 +18,7 @@ function check_player_state { fi } +# prevent sleep (and backup original state) function prevent_sleep { # take note of original settings gsettings get org.gnome.settings-daemon.plugins.power \ @@ -29,6 +32,7 @@ function prevent_sleep { sleep-inactive-ac-type 'nothing' } +# reset settings to original state function reset_settings { # recover original settings from state file orig_ba=`sed -n 1p $ORIGSTATE` @@ -40,13 +44,21 @@ function reset_settings { sleep-inactive-ac-type $orig_ac } +# Execution ------------------------------------------------------------------- + +# reset settings if specified (and exists). if [[ "$1" == "reset" ]]; then - reset_settings + if [[ -d $ORIGSTATE ]]; then + reset_settings + else + echo "Original State can not be restored. Exiting..." + exit 1 + fi else # initiate state file echo "false" > $STATEFILE - # run loop + # execute suspend-guard while :; do CURRENT_STATE=`cat $STATEFILE` SHOULD_STATE=`check_player_state "$SUPPAPP"` @@ -61,7 +73,7 @@ else echo "uninhibit sleep" fi fi - sleep $TIMEOUT + sleep $TIMEOUT # Zzzz... done fi