From 411a8955a02ed5d7a68ea7c13e973cd32f826bbb Mon Sep 17 00:00:00 2001 From: Harzo Date: Sat, 27 May 2023 17:53:26 +0200 Subject: [PATCH] checkupdates: Fix for shared module Cache result of checkupdates in temporary file, that gets updated after 15 seconds. It's a workaround for shared custom/pacman module that can only run for one bar at once. Usually it causes the module to work only in one bar. This way all bars should show the same output. --- .config/waybar/scripts/checkupdates | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/.config/waybar/scripts/checkupdates b/.config/waybar/scripts/checkupdates index 62022d1..6b963ed 100755 --- a/.config/waybar/scripts/checkupdates +++ b/.config/waybar/scripts/checkupdates @@ -1,5 +1,26 @@ #!/bin/sh -count="$(checkupdates-with-aur | wc -l)" +count_file=/tmp/waybar/module/pacman/count +threshold_date="$(date -d 'now - 15 seconds' +%s)" + +while pgrep checkupdates | grep -v $$; do + sleep 1 +done + +if [ -f "$count_file" ]; then + last_update="$(stat --format='%Y' "$count_file")" + if [ "$last_update" -ge "$threshold_date" ]; then + count="$(cat "$count_file")" + else + count="$(checkupdates-with-aur | wc -l)" + mkdir -p /tmp/waybar/module/pacman + echo "$count" > /tmp/waybar/module/pacman/count + fi +else + count="$(checkupdates-with-aur | wc -l)" + mkdir -p /tmp/waybar/module/pacman + echo "$count" > /tmp/waybar/module/pacman/count +fi + class="ok" if [ "$count" -gt 0 ]; then