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.
This commit is contained in:
Harzo 2023-05-27 17:53:26 +02:00
parent 9b19f29c3f
commit 411a8955a0
1 changed files with 22 additions and 1 deletions

View File

@ -1,5 +1,26 @@
#!/bin/sh
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