fix(action): sample getevent in 1s bursts
The piped getevent stream block-buffered on Magisk's BusyBox ash and missed a single vol-key press before the timeout. Sample getevent in 1s timeout bursts in a deadline loop instead.
This commit is contained in:
+8
-15
@@ -16,23 +16,16 @@ echo " 🔉 $(_msg confirm_vol_down)"
|
|||||||
echo " "
|
echo " "
|
||||||
|
|
||||||
confirm() {
|
confirm() {
|
||||||
vol_tmp="${TMPDIR:-/data/local/tmp}/teesim_vol_key"
|
# Sample getevent in 1s bursts; a piped stream block-buffers and misses
|
||||||
: > "$vol_tmp"
|
# a single key-press before the timeout.
|
||||||
|
deadline=$(( $(date +%s) + 10 ))
|
||||||
# Stream getevent and match VOLUME DOWN inline. Single-event sampling
|
while [ "$(date +%s)" -lt "$deadline" ]; do
|
||||||
# (`getevent -c 1`) races with EV_SYN/EV_MSC noise on Magisk's BusyBox ash.
|
events=$(/system/bin/timeout 1 /system/bin/getevent -l 2>/dev/null)
|
||||||
/system/bin/timeout 10 /system/bin/sh -c '
|
case "$events" in
|
||||||
/system/bin/getevent -lq 2>/dev/null | while IFS= read -r line; do
|
*KEY_VOLUMEUP*) return 0 ;;
|
||||||
case "$line" in
|
*KEY_VOLUMEDOWN*) return 1 ;;
|
||||||
*KEY_VOLUMEUP*DOWN*) echo UP > "$1"; exit 0 ;;
|
|
||||||
*KEY_VOLUMEDOWN*DOWN*) echo DOWN > "$1"; exit 0 ;;
|
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
' _ "$vol_tmp"
|
|
||||||
|
|
||||||
key=$(cat "$vol_tmp" 2>/dev/null)
|
|
||||||
rm -f "$vol_tmp"
|
|
||||||
[ "$key" = "UP" ] && return 0
|
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user