diff --git a/hosts/modules/gui/sxmo/default.nix b/hosts/modules/gui/sxmo/default.nix index 2c20da18e..bd38261f1 100644 --- a/hosts/modules/gui/sxmo/default.nix +++ b/hosts/modules/gui/sxmo/default.nix @@ -87,6 +87,11 @@ let src = ./hooks; pkgs = [ "superd" "xdg-user-dirs" ]; }; + suspend = pkgs.static-nix-shell.mkBash { + pname = "sxmo_suspend.sh"; + src = ./hooks; + pkgs = [ "coreutils" "util-linux" ]; + }; }; in { @@ -176,6 +181,7 @@ in "sxmo_hook_postwake.sh" = "${hookPkgs.postwake}/bin/sxmo_hook_postwake.sh"; "sxmo_hook_rotate.sh" = "${hookPkgs.rotate}/bin/sxmo_hook_rotate.sh"; "sxmo_hook_start.sh" = "${hookPkgs.start}/bin/sxmo_hook_start.sh"; + "sxmo_suspend.sh" = "${hookPkgs.suspend}/bin/sxmo_suspend.sh"; }; description = '' extra hooks to add with higher priority than the builtins diff --git a/hosts/modules/gui/sxmo/hooks/sxmo_suspend.sh b/hosts/modules/gui/sxmo/hooks/sxmo_suspend.sh new file mode 100755 index 000000000..1deede2f3 --- /dev/null +++ b/hosts/modules/gui/sxmo/hooks/sxmo_suspend.sh @@ -0,0 +1,39 @@ +#!/usr/bin/env nix-shell +#!nix-shell -i bash -p coreutils -p util-linux + +# yeah, this isn't technically a hook, but the hook infrastructure isn't actually +# restricted to stuff that starts with sxmo_hook_ ... +# +# this script is only called by sxmo_autosuspend, which is small, so if i wanted to +# be more proper i could instead re-implement autosuspend + integrations. + +. sxmo_common.sh + +sxmo_log "going to suspend to crust" + +YEARS8_TO_SEC=268435455 +suspend_time=99999999 # far away + +mnc="$(sxmo_hook_mnc.sh)" +if [ -n "$mnc" ] && [ "$mnc" -gt 0 ] && [ "$mnc" -lt "$YEARS8_TO_SEC" ]; then + if [ "$mnc" -le 15 ]; then # cronjob imminent + sxmo_wakelock.sh lock sxmo_waiting_cronjob infinite + exit 1 + else + suspend_time=$((mnc - 10)) + fi +fi + +sxmo_log "calling suspend with suspend_time <$suspend_time>" + +start="$(date "+%s")" +rtcwake -m mem -s "$suspend_time" || exit 1 +#We woke up again +time_spent="$(( $(date "+%s") - start ))" + +if [ "$((time_spent + 15))" -ge "$suspend_time" ]; then + sxmo_wakelock.sh lock sxmo_waiting_cronjob infinite +fi + +sxmo_hook_postwake.sh +