swaync: move the pkill logic into swaync-fbcli
This commit is contained in:
@@ -2,21 +2,6 @@
|
||||
# it describes special things to do in response to specific notifications,
|
||||
# e.g. sound a ringer when we get a call, ...
|
||||
{ pkgs }:
|
||||
let
|
||||
# we do this because swaync's exec naively splits the command on space to produce its argv, rather than parsing the shell.
|
||||
# [ "pkill" "-f" "fbcli" "--event" ... ] -> breaks pkill
|
||||
# [ "pkill" "-f" "fbcli --event ..." ] -> is what we want
|
||||
fbcli-stop-wrapper = pkgs.writeShellApplication {
|
||||
name = "fbcli-stop";
|
||||
runtimeInputs = [
|
||||
pkgs.procps # for pkill
|
||||
];
|
||||
text = ''
|
||||
pkill -e -f "swaync-fbcli $*"
|
||||
'';
|
||||
};
|
||||
fbcli-stop = "${fbcli-stop-wrapper}/bin/fbcli-stop";
|
||||
in
|
||||
{
|
||||
# a script can match regex on these fields. only fired if all listed fields match:
|
||||
# - app-name
|
||||
@@ -43,39 +28,39 @@ in
|
||||
# should also be possible to trigger via any messaging app
|
||||
fbcli-test-im = {
|
||||
body = "test:message";
|
||||
exec = "swaync-fbcli --event proxied-message-new-instant";
|
||||
exec = "swaync-fbcli start --event proxied-message-new-instant";
|
||||
};
|
||||
fbcli-test-call = {
|
||||
body = "test:call";
|
||||
exec = "swaync-fbcli --event phone-incoming-call -t 20";
|
||||
exec = "swaync-fbcli start --event phone-incoming-call -t 20";
|
||||
};
|
||||
fbcli-test-call-stop = {
|
||||
body = "test:call-stop";
|
||||
exec = "${fbcli-stop} --event phone-incoming-call -t 20'";
|
||||
exec = "swaync-fbcli stop --event phone-incoming-call -t 20'";
|
||||
};
|
||||
|
||||
incoming-im-known-app-name = {
|
||||
# trigger notification sound on behalf of these IM clients.
|
||||
app-name = "(Chats|Dino|discord|dissent|Element|Fractal)";
|
||||
body = "^(?!Incoming call).*$"; #< don't match Dino Incoming calls
|
||||
exec = "swaync-fbcli --event proxied-message-new-instant";
|
||||
exec = "swaync-fbcli start --event proxied-message-new-instant";
|
||||
};
|
||||
incoming-im-known-desktop-entry = {
|
||||
# trigger notification sound on behalf of these IM clients.
|
||||
# these clients don't have an app-name (listed as "<unknown>"), but do have a desktop-entry
|
||||
desktop-entry = "com.github.uowuo.abaddon";
|
||||
exec = "swaync-fbcli --event proxied-message-new-instant";
|
||||
exec = "swaync-fbcli start --event proxied-message-new-instant";
|
||||
};
|
||||
incoming-call = {
|
||||
app-name = "Dino";
|
||||
body = "^Incoming call$";
|
||||
exec = "swaync-fbcli --event phone-incoming-call -t 20";
|
||||
exec = "swaync-fbcli start --event phone-incoming-call -t 20";
|
||||
};
|
||||
incoming-call-acted-on = {
|
||||
# when the notification is clicked, stop sounding the ringer
|
||||
app-name = "Dino";
|
||||
body = "^Incoming call$";
|
||||
run-on = "action";
|
||||
exec = "${fbcli-stop} --event phone-incoming-call -t 20";
|
||||
exec = "swaync-fbcli stop --event phone-incoming-call -t 20";
|
||||
};
|
||||
}
|
||||
|
@@ -1,12 +1,9 @@
|
||||
#!/usr/bin/env nix-shell
|
||||
#!nix-shell -i bash -p feedbackd -p procps -p swaynotificationcenter
|
||||
|
||||
# if in Do Not Disturb, don't do any feedback
|
||||
# TODO: better solution is to actually make use of feedbackd profiles.
|
||||
# i.e. set profile to `quiet` when in DnD mode
|
||||
if [ "$SWAYNC_URGENCY" != "Critical" ] && [ "$(swaync-client --get-dnd)" = "true" ]; then
|
||||
exit
|
||||
fi
|
||||
action="$1"
|
||||
shift
|
||||
fbcliargs=("$@")
|
||||
|
||||
# kill children if killed, to allow that killing this parent process will end the real fbcli call
|
||||
cleanup() {
|
||||
@@ -14,12 +11,35 @@ cleanup() {
|
||||
pkill -P "$child"
|
||||
exit 0 # exit cleanly to avoid swaync alerting a script failure
|
||||
}
|
||||
trap cleanup SIGINT SIGQUIT SIGTERM
|
||||
|
||||
# feedbackd stops playback when the caller exits
|
||||
# and fbcli will exit immediately if it has no stdin.
|
||||
# so spoof a stdin.
|
||||
# TODO: this maybe pegs CPU at 100% when receiving a call, and never exits?
|
||||
/bin/sh -c "true | fbcli $*" &
|
||||
child=$!
|
||||
wait
|
||||
start() {
|
||||
# if in Do Not Disturb, don't do any feedback
|
||||
# TODO: better solution is to actually make use of feedbackd profiles.
|
||||
# i.e. set profile to `quiet` when in DnD mode
|
||||
if [ "$SWAYNC_URGENCY" != "Critical" ] && [ "$(swaync-client --get-dnd)" = "true" ]; then
|
||||
exit
|
||||
fi
|
||||
|
||||
trap cleanup SIGINT SIGQUIT SIGTERM
|
||||
|
||||
# feedbackd stops playback when the caller exits
|
||||
# and fbcli will exit immediately if it has no stdin.
|
||||
# so spoof a stdin.
|
||||
# TODO: this maybe pegs CPU at 100% when receiving a call, and never exits?
|
||||
/bin/sh -c "true | fbcli ${fbcliargs[*]}" &
|
||||
child=$!
|
||||
wait
|
||||
}
|
||||
|
||||
stop() {
|
||||
pkill -e -f "swaync-fbcli start ${fbcliargs[*]}"
|
||||
}
|
||||
|
||||
case "$action" in
|
||||
start)
|
||||
start
|
||||
;;
|
||||
stop)
|
||||
stop
|
||||
;;
|
||||
esac
|
||||
|
Reference in New Issue
Block a user