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