Fixed wob showing when starting up or running some apps

This commit is contained in:
ManOfGoldForever 2026-04-07 12:35:18 -04:00
parent 29e0e5db25
commit b032bd5f28

View file

@ -1,17 +1,44 @@
#!/bin/bash
# Wait for pipewire/pulseaudio to be ready
until pactl info &>/dev/null; do
sleep 0.5
done
WOB_SOCK="${XDG_RUNTIME_DIR}/wob.sock"
sleep 3
pactl subscribe 2>/dev/null | grep --line-buffered "sink" | while read -r _; do
vol=$(pactl get-sink-volume @DEFAULT_SINK@ | grep -oP '\d+(?=%)' | head -1)
muted=$(pactl get-sink-mute @DEFAULT_SINK@ | grep -c yes)
if [ "$muted" -gt 0 ]; then
WOB_SOCK="${XDG_RUNTIME_DIR}/wob.sock"
prev_vol=""
prev_muted=""
get_vol() {
pactl get-sink-volume @DEFAULT_SINK@ 2>/dev/null | grep -oP '\d+(?=%)' | head -1
}
get_muted() {
pactl get-sink-mute @DEFAULT_SINK@ 2>/dev/null | grep -q yes && echo 1 || echo 0
}
pactl subscribe 2>/dev/null | grep --line-buffered "^Event 'change' on sink #" | while read -r _; do
# First read
vol1=$(get_vol)
muted1=$(get_muted)
# Wait and read again — if still changing (app connecting) the values won't match
sleep 0.25
vol2=$(get_vol)
muted2=$(get_muted)
# Skip if unstable
[ "$vol1" != "$vol2" ] || [ "$muted1" != "$muted2" ] && continue
# Skip if nothing changed from last shown value
[ "$vol2" = "$prev_vol" ] && [ "$muted2" = "$prev_muted" ] && continue
prev_vol="$vol2"
prev_muted="$muted2"
if [ "$muted2" = "1" ]; then
echo 0 > "$WOB_SOCK"
else
echo "$vol" > "$WOB_SOCK"
echo "$vol2" > "$WOB_SOCK"
fi
done