waybar: Add security key interaction notification

reuse
Simon Bruder 2024-01-22 17:19:48 +01:00
parent 013511c1c9
commit ec150e5a6c
Signed by: simon
GPG Key ID: 347FF8699CDA0776
5 changed files with 88 additions and 2 deletions

8
LICENSES/ISC.txt Normal file
View File

@ -0,0 +1,8 @@
ISC License:
Copyright (c) 2004-2010 by Internet Systems Consortium, Inc. ("ISC")
Copyright (c) 1995-2003 by Internet Software Consortium
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

View File

@ -27,4 +27,17 @@
maxCacheTtl = 1800;
maxCacheTtlSsh = maxCacheTtl;
};
systemd.user.services.yubikey-touch-detector = {
Unit.PartOf = [ "sway-session.target" ];
Install.WantedBy = [ "sway-session.target" ];
Service = {
Environment = [
"PATH=${pkgs.gnupg}/bin"
];
ExecStart = "${pkgs.yubikey-touch-detector}/bin/yubikey-touch-detector";
Restart = "on-failure";
};
};
}

View File

@ -0,0 +1,45 @@
#! @bash@/bin/bash
# shellcheck disable=SC2239
# SPDX-FileCopyrightText: 2020 Maxim Baz <git@maximbaz.com>
# SPDX-FileCopyrightText: 2023 Matthew Monaco <matt@monaco.cx>
# SPDX-FileCopyrightText: 2024 Simon Bruder <simon@sbruder.de>
#
# SPDX-License-Identifier: ISC
set -euo pipefail
socket="${XDG_RUNTIME_DIR:-/run/user/$UID}/yubikey-touch-detector.socket"
while true; do
touch_reasons=()
if [ ! -e "$socket" ]; then
printf '{"text": "Waiting for socket"}\n'
while [ ! -e "$socket" ]; do sleep 1; done
fi
printf '{"text": ""}\n'
while read -r -n5 cmd; do
reason="${cmd:0:3}"
if [ "${cmd:4:1}" = "1" ]; then
touch_reasons+=("$reason")
else
for i in "${!touch_reasons[@]}"; do
if [ "${touch_reasons[i]}" = "$reason" ]; then
unset 'touch_reasons[i]'
break
fi
done
fi
if [ "${#touch_reasons[@]}" -eq 0 ]; then
printf '{"text": ""}\n'
else
tooltip="Security key is waiting for a touch, reasons: ${touch_reasons[*]}"
printf '{"text": "󰈷", "tooltip": "%s"}\n' "$tooltip"
fi
done < <(@netcat@/bin/nc -U "$socket")
sleep 1
done

View File

@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2020-2022 Simon Bruder <simon@sbruder.de>
* SPDX-FileCopyrightText: 2020-2024 Simon Bruder <simon@sbruder.de>
*
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
@ -178,3 +178,13 @@ window#waybar {
background-color: @base3@;
color: @base00@;
}
#custom-interaction {
background-color: @yellow@;
color: @base03@;
animation-name: blink;
animation-duration: 0.5s;
animation-timing-function: cubic-bezier(1, 0, 0, 1);
animation-iteration-count: infinite;
animation-direction: alternate;
}

View File

@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: 2020-2023 Simon Bruder <simon@sbruder.de>
# SPDX-FileCopyrightText: 2020-2024 Simon Bruder <simon@sbruder.de>
#
# SPDX-License-Identifier: AGPL-3.0-or-later
@ -37,6 +37,7 @@ in
];
modules-right = [
"tray"
"custom/interaction"
"custom/screencast"
"custom/redshift"
"idle_inhibitor"
@ -81,6 +82,15 @@ in
deactivated = "󰈉 ";
};
};
"custom/interaction" = {
exec = pkgs.substituteAll ({
src = ./waybar-interaction;
} // {
inherit (pkgs) netcat bash;
isExecutable = true;
});
return-type = "json";
};
"custom/screencast" = {
exec = pkgs.writeScript "screencast-monitor" /* python */ ''
#!${pkgs.python3}/bin/python3