swaync-fbcli: fix so that the child actually exits when killed (critical is to use SIGINT)
This commit is contained in:
@@ -11,6 +11,8 @@ log() {
|
||||
fi
|
||||
}
|
||||
|
||||
child=
|
||||
|
||||
# kill children if killed, to allow that killing this parent process will end the real fbcli call
|
||||
cleanup() {
|
||||
log "aborting fbcli notification (PID $child)"
|
||||
@@ -18,6 +20,28 @@ cleanup() {
|
||||
exit 0 # exit cleanly to avoid swaync alerting a script failure
|
||||
}
|
||||
|
||||
startInline() {
|
||||
local timeout=
|
||||
case "$event" in
|
||||
phone-incoming-call)
|
||||
timeout=20
|
||||
;;
|
||||
*)
|
||||
;;
|
||||
esac
|
||||
|
||||
fbcliArgs=(fbcli --event "$event")
|
||||
if [ -n "$timeout" ]; then
|
||||
fbcliArgs+=(-t "$timeout")
|
||||
fi
|
||||
|
||||
# feedbackd stops playback when the caller exits
|
||||
# and fbcli will exit immediately if it has no stdin.
|
||||
# so spoof a stdin.
|
||||
log "${fbcliArgs[*]}"
|
||||
sleep $((3 + ${timeout:+ + $timeout})) | ${fbcliArgs[@]}
|
||||
}
|
||||
|
||||
start() {
|
||||
# if in Do Not Disturb, don't do any feedback
|
||||
# TODO: better solution is to actually make use of feedbackd profiles.
|
||||
@@ -28,34 +52,22 @@ start() {
|
||||
|
||||
trap cleanup SIGINT SIGQUIT SIGTERM
|
||||
|
||||
local timeout=
|
||||
case "$event" in
|
||||
phone-incoming-call)
|
||||
timeout=20
|
||||
;;
|
||||
*)
|
||||
;;
|
||||
esac
|
||||
|
||||
local cli="fbcli --event $event ${timeout:+ -t $timeout}"
|
||||
|
||||
# feedbackd stops playback when the caller exits
|
||||
# and fbcli will exit immediately if it has no stdin.
|
||||
# so spoof a stdin.
|
||||
log "$cli"
|
||||
/bin/sh -c "sleep $((3 ${timeout:+ + $timeout})) | $cli" &
|
||||
startInline &
|
||||
child=$!
|
||||
wait
|
||||
}
|
||||
|
||||
stop() {
|
||||
pkill -e -f "swaync-fbcli(-wrapped)? start $event"
|
||||
pkill --echo --signal SIGINT --full "swaync-fbcli(-wrapped)? start $event"
|
||||
}
|
||||
|
||||
case "$action" in
|
||||
start)
|
||||
start
|
||||
;;
|
||||
startInline)
|
||||
startInline # support this for debugging
|
||||
;;
|
||||
stop)
|
||||
stop
|
||||
;;
|
||||
|
Reference in New Issue
Block a user