From 3b4d97ac79023f16597813d0f05b8426762ac6fc Mon Sep 17 00:00:00 2001 From: Price Hiller Date: Thu, 9 Jan 2025 22:37:40 -0600 Subject: [PATCH] perf(waybar): only send media updates when necessary --- .../.config/waybar/scripts/get-media.bash | 31 +++++++++---------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/users/price/dots/.config/waybar/scripts/get-media.bash b/users/price/dots/.config/waybar/scripts/get-media.bash index a805d3a4..c87829aa 100755 --- a/users/price/dots/.config/waybar/scripts/get-media.bash +++ b/users/price/dots/.config/waybar/scripts/get-media.bash @@ -3,30 +3,29 @@ get-album-info() { local class 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="$(playerctl metadata --format '{{lc(status)}}')"; then - local player_ctl_info - player_ctl_info="$(playerctl metadata --format '{{ artist }} | {{ title }} | {{ album }}')" + if [[ "${class}" == "playing" ]]; then + text="󰎆 ${player_ctl_info}" - if [[ "${class}" == "playing" ]]; then - text="󰎆 ${player_ctl_info}" - - elif [[ "${class}" == "paused" ]]; then - text="󰏦 ${player_ctl_info}" - fi - else - class="paused" - text="󰓄 No Media" + elif [[ "${class}" == "paused" ]]; then + text="󰏦 ${player_ctl_info}" fi + else + class="paused" + text="󰓄 No Media" + fi - printf '{"class": "%s", "text": "%s"}\n' "${class}" "${text}" - sleep .5 - done + printf '{"class": "%s", "text": "%s"}\n' "${class}" "${text}" } main() { 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