From 81c16ec47925934630643ef20e47ae9637dfee50 Mon Sep 17 00:00:00 2001 From: Colin Date: Sat, 16 Sep 2023 05:06:41 +0000 Subject: [PATCH] swaync/feedbackd: activate ringer on incoming dino call --- hosts/common/programs/feedbackd.nix | 32 ++++++++++++++ .../programs/swaynotificationcenter.nix | 43 +++++++++++++++++-- 2 files changed, 72 insertions(+), 3 deletions(-) diff --git a/hosts/common/programs/feedbackd.nix b/hosts/common/programs/feedbackd.nix index b4e9b14e..7a5afdfe 100644 --- a/hosts/common/programs/feedbackd.nix +++ b/hosts/common/programs/feedbackd.nix @@ -23,6 +23,32 @@ in # N.B.: feedbackd will load ~/.config/feedbackd/themes/default.json by default # - but using that would forbid `parent-theme = "default"` + # the default theme ships support for these events: + # - alarm-clock-elapsed + # - alarm-clock-elapsed + # - battery-caution + # - bell-terminal + # - button-pressed + # - button-released + # - camera-focus + # - camera-shutter + # - message-missed-email + # - message-missed-instant + # - message-missed-notification + # - message-missed-sms + # - message-new-email + # - message-new-instant + # - message-new-sms + # - message-sent-instant + # - phone-failure + # - phone-hangup + # - phone-incoming-call + # - phone-missed-call + # - phone-outgoing-busy + # - screen-capture + # - theme-demo + # - timeout-completed + # - window-close fs.".config/feedbackd/themes/proxied.json".symlink.text = builtins.toJSON { name = "proxied"; parent-theme = "default"; @@ -40,6 +66,12 @@ in type = "Sound"; effect = "message-new-instant"; } + { + # i guess we aren't actually inheriting from the default theme? + event-name = "phone-incoming-call"; + type = "Sound"; + effect = "phone-incoming-call"; + } ]; } ]; diff --git a/hosts/common/programs/swaynotificationcenter.nix b/hosts/common/programs/swaynotificationcenter.nix index 1b2ded79..723c9346 100644 --- a/hosts/common/programs/swaynotificationcenter.nix +++ b/hosts/common/programs/swaynotificationcenter.nix @@ -21,24 +21,49 @@ let name = "swaync-fbcli"; runtimeInputs = [ config.sane.programs.feedbackd.package + pkgs.procps # for pkill cfg.package ]; text = '' # 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-client --get-dnd)" = "true" ]; then + 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 + cleanup() { + echo "aborting fbcli notification (PID $child)" + 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: - true | fbcli "$@" + /bin/sh -c "true | fbcli $*" & + child=$! + wait ''; }; fbcli = "${fbcli-wrapper}/bin/swaync-fbcli"; + # 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 "${fbcli} $*" + ''; + }; + fbcli-stop = "${fbcli-stop-wrapper}/bin/fbcli-stop"; + systemctl-toggle = pkgs.writeShellApplication { name = "systemctl-toggle"; runtimeInputs = [ @@ -152,9 +177,21 @@ in # - SWAYNC_SUMMARY sound-im = { # trigger notification sound on behalf of these IM clients. - # TODO: dispatch calls separately! exec = "${fbcli} --event proxied-message-new-instant"; app-name = "(Chats|Dino|discord|Element)"; + body = "^(?!Incoming call).*$"; #< don't match Dino Incoming calls + }; + sound-call = { + exec = "${fbcli} --event phone-incoming-call -t 20"; + app-name = "Dino"; + body = "^Incoming call$"; + }; + sound-call-end = { + # pkill will kill all processes matching -- not just the first + exec = "${fbcli-stop} --event phone-incoming-call -t 20"; + app-name = "Dino"; + body = "^Incoming call$"; + run-on = "action"; }; }; notification-visibility = {