sxmo_timer.sh: allow suspension while running
To do this, we implement a new sxmo_sleep program that is a sleep but that can wake the device from suspension when the timer expires. Also, stopwatch can perfectly survive a suspension. So we don't have to wakelock on this.
This commit is contained in:
@@ -6,13 +6,34 @@
|
||||
# shellcheck source=scripts/core/sxmo_common.sh
|
||||
. sxmo_common.sh
|
||||
|
||||
_finish_timerrun() {
|
||||
_releasealarm
|
||||
exit
|
||||
}
|
||||
|
||||
_setupalarm() {
|
||||
sxmo_sleep -c boottime_alarm "$1" &
|
||||
alarmpid=$!
|
||||
}
|
||||
|
||||
_releasealarm() {
|
||||
if [ -n "$alarmpid" ]; then
|
||||
kill "$alarmpid" 2> /dev/null
|
||||
unset alarmpid
|
||||
fi
|
||||
}
|
||||
|
||||
timerrun() {
|
||||
trap '_finish_timerrun' INT TERM EXIT
|
||||
|
||||
TIME="$(
|
||||
echo "$@" |
|
||||
sed 's/\([^0-9]\)\([0-9]\)/\1+\2/g; s/h/*60m/g; s/m/*60s/g; s/s//g' |
|
||||
bc
|
||||
)"
|
||||
|
||||
_setupalarm "$TIME"
|
||||
|
||||
DATE1="$(($(date +%s) + TIME))";
|
||||
while [ "$DATE1" -ge "$(date +%s)" ]; do
|
||||
printf "%s\r" "$(date -u --date @$((DATE1 - $(date +%s))) +%H:%M:%S)";
|
||||
@@ -20,6 +41,8 @@ timerrun() {
|
||||
done
|
||||
echo "Done with $*"
|
||||
|
||||
_releasealarm
|
||||
|
||||
while : ;
|
||||
do notify-send "Done with $*";
|
||||
sxmo_vibrate 1000 "${SXMO_VIBRATE_STRENGTH:-1}"
|
||||
@@ -27,10 +50,6 @@ timerrun() {
|
||||
done
|
||||
}
|
||||
|
||||
cleanwakelock() {
|
||||
sxmo_wakelock.sh unlock sxmo_"$(basename "$0")"
|
||||
}
|
||||
|
||||
stopwatchrun() {
|
||||
start="$(date +%s)"
|
||||
while : ; do
|
||||
@@ -63,13 +82,9 @@ EOF
|
||||
exit 0
|
||||
;;
|
||||
"Stopwatch")
|
||||
sxmo_wakelock.sh lock sxmo_"$(basename "$0")" infinite
|
||||
trap 'cleanwakelock' INT TERM EXIT
|
||||
sxmo_terminal.sh "$0" stopwatchrun
|
||||
;;
|
||||
*)
|
||||
sxmo_wakelock.sh lock sxmo_"$(basename "$0")" infinite
|
||||
trap 'cleanwakelock' INT TERM EXIT
|
||||
sxmo_terminal.sh "$0" timerrun "$TIMEINPUT"
|
||||
;;
|
||||
esac
|
||||
|
Reference in New Issue
Block a user