sxmo: block suspend if go2tv is active

This commit is contained in:
Colin 2024-01-01 04:56:39 +00:00
parent c54df8d9c4
commit 6fe195e2dd
2 changed files with 45 additions and 1 deletions

View File

@ -68,6 +68,11 @@ let
'';
hookPkgs = {
block_suspend = pkgs.static-nix-shell.mkBash {
pname = "sxmo_hook_block_suspend.sh";
pkgs = [ "procps" ];
src = ./hooks;
};
inputhandler = pkgs.static-nix-shell.mkBash {
pname = "sxmo_hook_inputhandler.sh";
pkgs = [ "coreutils" "playerctl" "pulseaudio" ];
@ -150,7 +155,7 @@ in
# by including hooks here, updating the sxmo package also updates the hooks
# without requiring any reboot
"sxmo_hook_apps.sh" = "${package}/share/sxmo/default_hooks/sxmo_hook_apps.sh";
"sxmo_hook_block_suspend.sh" = "${package}/share/sxmo/default_hooks/sxmo_hook_block_suspend.sh";
# "sxmo_hook_block_suspend.sh" = "${package}/share/sxmo/default_hooks/sxmo_hook_block_suspend.sh";
"sxmo_hook_call_audio.sh" = "${package}/share/sxmo/default_hooks/sxmo_hook_call_audio.sh";
"sxmo_hook_contextmenu_fallback.sh" = "${package}/share/sxmo/default_hooks/sxmo_hook_contextmenu_fallback.sh";
"sxmo_hook_contextmenu.sh" = "${package}/share/sxmo/default_hooks/sxmo_hook_contextmenu.sh";
@ -186,6 +191,7 @@ in
"sxmo_hook_tailtextlog.sh" = "${package}/share/sxmo/default_hooks/sxmo_hook_tailtextlog.sh";
} // {
# default hooks for this nix module, not upstreamable
"sxmo_hook_block_suspend.sh" = "${hookPkgs.block_suspend}/bin/sxmo_hook_block_suspend.sh";
"sxmo_hook_inputhandler.sh" = "${hookPkgs.inputhandler}/bin/sxmo_hook_inputhandler.sh";
"sxmo_hook_postwake.sh" = "${hookPkgs.postwake}/bin/sxmo_hook_postwake.sh";
"sxmo_hook_rotate.sh" = "${hookPkgs.rotate}/bin/sxmo_hook_rotate.sh";

View File

@ -0,0 +1,38 @@
#!/usr/bin/env nix-shell
#!nix-shell -i bash -p procps
wait_item() {
while $1 > /dev/null 2>&1; do
waited=1
sleep 1
done
}
casting_go2tv() {
pgrep -f go2tv
}
while [ "$waited" != "0" ]; do
waited=0
wait_item casting_go2tv
# forward to the next block_suspend.sh script (if any).
# have to handle the case where this script is on PATH, and also when it was called without being on PATH.
# the implementation here causes us to call ourselves exactly once, at most.
SXMO_HOOK_BLOCK_SUSPEND_DEPTH=$((${SXMO_HOOK_BLOCK_SUSPEND_DEPTH:-0} + 1))
echo "recurse counter: $SXMO_HOOK_BLOCK_SUSPEND_DEPTH"
FWD_COUNT=0
IFS=:
for p in $PATH ; do
echo "testing: $p/sxmo_hook_block_suspend.sh"
if $(test -x "$p/sxmo_hook_block_suspend.sh"); then
FWD_COUNT=$(($FWD_COUNT + 1))
fi
if [ "$FWD_COUNT" -eq "$SXMO_HOOK_BLOCK_SUSPEND_DEPTH" ]; then
echo "forwarding to: $p/sxmo_hook_block_suspend.sh"
"$p/sxmo_hook_block_suspend.sh"
fi
done
done