Add an indicator to FreeBSD for when recording is active.

This commit is contained in:
Tom Alexander
2022-11-29 00:15:48 -05:00
parent 019b4184ce
commit 8ea4ca15d8
4 changed files with 70 additions and 1 deletions

View File

@@ -0,0 +1,57 @@
#!/usr/bin/env bash
#
# Report screen recording status in FreeBSD
set -euo pipefail
IFS=$'\n\t'
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
SLEEP_INTERVAL=${SLEEP_INTERVAL:-10}
function main {
local previous_reported="-1"
stream_key_binding_activations | while read -t "$SLEEP_INTERVAL" event; do
if pgrep -q wf-recorder; then
local is_running=1
else
local is_running=0
fi
if [ "$is_running" -ne "$previous_reported" ]; then
previous_reported="$is_running"
report "$is_running"
fi
done
while true; do
sleep $SLEEP_INTERVAL
done
}
function stream_key_binding_activations {
swaymsg --raw --monitor --type subscribe '[ "binding" ]'
}
function report {
is_running="$1"
if [ "$is_running" -eq 0 ]; then
jq --unbuffered --compact-output <<EOF
{
"text":"",
"tooltip":"Not recording",
"percentage":0,
"class":"hidden"
}
EOF
else
jq --unbuffered --compact-output <<EOF
{
"text":"⏺",
"tooltip":"Recording",
"percentage":100,
"class":"visible"
}
EOF
fi
}
main "${@}"