perf(waybar): only send media updates when necessary
Some checks failed
Check Formatting of Files / Check-Formatting (push) Failing after 37s

This commit is contained in:
Price Hiller 2025-01-09 22:37:40 -06:00
parent 4b0fba074b
commit 3b4d97ac79
Signed by: Price
GPG Key ID: C3FADDE7A8534BEB

View File

@ -3,30 +3,29 @@
get-album-info() { get-album-info() {
local class local class
local text="" local text=""
if class="$(playerctl metadata --format '{{lc(status)}}')"; then
local player_ctl_info
player_ctl_info="$(playerctl metadata --format '{{ artist }} | {{ title }} | {{ album }}')"
while :; do if [[ "${class}" == "playing" ]]; then
if class="$(playerctl metadata --format '{{lc(status)}}')"; then text="󰎆 ${player_ctl_info}"
local player_ctl_info
player_ctl_info="$(playerctl metadata --format '{{ artist }} | {{ title }} | {{ album }}')"
if [[ "${class}" == "playing" ]]; then elif [[ "${class}" == "paused" ]]; then
text="󰎆 ${player_ctl_info}" text="󰏦 ${player_ctl_info}"
elif [[ "${class}" == "paused" ]]; then
text="󰏦 ${player_ctl_info}"
fi
else
class="paused"
text="󰓄 No Media"
fi fi
else
class="paused"
text="󰓄 No Media"
fi
printf '{"class": "%s", "text": "%s"}\n' "${class}" "${text}" printf '{"class": "%s", "text": "%s"}\n' "${class}" "${text}"
sleep .5
done
} }
main() { main() {
get-album-info get-album-info
while IFS= read -r _; do
get-album-info
done < <(busctl --user monitor --json=short --match 'interface=org.mpris.MediaPlayer2.Player,type=signal')
} }
main main