swaync: split the fbcli wrapper into its own file
This commit is contained in:
parent
590cb2dd7f
commit
3d3618256d
|
@ -33,6 +33,18 @@ in
|
|||
};
|
||||
};
|
||||
|
||||
sane.programs.swaync-fbcli = {
|
||||
packageUnwrapped = pkgs.static-nix-shell.mkBash {
|
||||
pname = "swaync-fbcli";
|
||||
srcRoot = ./.;
|
||||
pkgs = [
|
||||
"feedbackd"
|
||||
"procps"
|
||||
"swaynotificationcenter"
|
||||
];
|
||||
};
|
||||
};
|
||||
|
||||
sane.programs.swaynotificationcenter = {
|
||||
configOption = with lib; mkOption {
|
||||
type = types.submodule {
|
||||
|
@ -51,6 +63,11 @@ in
|
|||
|
||||
# prevent dbus from automatically activating swaync so i can manage it as a systemd service instead
|
||||
packageUnwrapped = pkgs.rmDbusServices pkgs.swaynotificationcenter;
|
||||
suggestedPrograms = [
|
||||
"feedbackd"
|
||||
"swaync-fbcli" #< used to sound ringer
|
||||
"swaync-service-dispatcher" #< used when toggling buttons
|
||||
];
|
||||
|
||||
sandbox.method = "bwrap";
|
||||
sandbox.whitelistAudio = true;
|
||||
|
@ -90,11 +107,6 @@ in
|
|||
# the glib code which consumes this is `g_notification_backend_new_default`, calling into `_g_io_module_get_default_type`.
|
||||
env.GNOTIFICATION_BACKEND = "freedesktop";
|
||||
|
||||
suggestedPrograms = [
|
||||
"feedbackd"
|
||||
"swaync-service-dispatcher" #< used when toggling buttons
|
||||
];
|
||||
|
||||
fs.".config/swaync/style.css".symlink.target = ./style.css;
|
||||
fs.".config/swaync/config.json".symlink.text = builtins.toJSON {
|
||||
"$schema" = "/etc/xdg/swaync/configSchema.json";
|
||||
|
|
|
@ -3,39 +3,6 @@
|
|||
# e.g. sound a ringer when we get a call, ...
|
||||
{ pkgs }:
|
||||
let
|
||||
fbcli-wrapper = pkgs.writeShellApplication {
|
||||
name = "swaync-fbcli";
|
||||
runtimeInputs = [
|
||||
pkgs.feedbackd
|
||||
pkgs.procps # for pkill
|
||||
pkgs.swaynotificationcenter
|
||||
];
|
||||
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_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:
|
||||
/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
|
||||
|
@ -45,7 +12,7 @@ let
|
|||
pkgs.procps # for pkill
|
||||
];
|
||||
text = ''
|
||||
pkill -e -f "${fbcli} $*"
|
||||
pkill -e -f "swaync-fbcli $*"
|
||||
'';
|
||||
};
|
||||
fbcli-stop = "${fbcli-stop-wrapper}/bin/fbcli-stop";
|
||||
|
@ -76,33 +43,33 @@ in
|
|||
# should also be possible to trigger via any messaging app
|
||||
fbcli-test-im = {
|
||||
body = "test:message";
|
||||
exec = "${fbcli} --event proxied-message-new-instant";
|
||||
exec = "swaync-fbcli --event proxied-message-new-instant";
|
||||
};
|
||||
fbcli-test-call = {
|
||||
body = "test:call";
|
||||
exec = "${fbcli} --event phone-incoming-call -t 20";
|
||||
exec = "swaync-fbcli --event phone-incoming-call -t 20";
|
||||
};
|
||||
fbcli-test-call-stop = {
|
||||
body = "test:call-stop";
|
||||
exec = "${fbcli-stop} --event phone-incoming-call -t 20";
|
||||
exec = "${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 = "${fbcli} --event proxied-message-new-instant";
|
||||
exec = "swaync-fbcli --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 = "${fbcli} --event proxied-message-new-instant";
|
||||
exec = "swaync-fbcli --event proxied-message-new-instant";
|
||||
};
|
||||
incoming-call = {
|
||||
app-name = "Dino";
|
||||
body = "^Incoming call$";
|
||||
exec = "${fbcli} --event phone-incoming-call -t 20";
|
||||
exec = "swaync-fbcli --event phone-incoming-call -t 20";
|
||||
};
|
||||
incoming-call-acted-on = {
|
||||
# when the notification is clicked, stop sounding the ringer
|
||||
|
|
25
hosts/common/programs/swaynotificationcenter/swaync-fbcli
Executable file
25
hosts/common/programs/swaynotificationcenter/swaync-fbcli
Executable file
|
@ -0,0 +1,25 @@
|
|||
#!/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
|
||||
|
||||
# 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.
|
||||
# TODO: this maybe pegs CPU at 100% when receiving a call, and never exits?
|
||||
/bin/sh -c "true | fbcli $*" &
|
||||
child=$!
|
||||
wait
|
Loading…
Reference in New Issue
Block a user