fix: Waybar-Wrapper gibt immer Output aus

Fallback-JSON wenn corsairctl fehlschlägt oder Cache leer ist.
flock -w 5 statt -n damit der zweite Prozess wartet statt
sofort aufzugeben. Atomares mv statt direktem Schreiben in Cache.
This commit is contained in:
nevaforget 2026-03-27 23:46:19 +01:00
parent 95802c5d37
commit 186a65ee86

View File

@ -5,9 +5,10 @@
CACHE="/tmp/corsairctl-waybar.json"
LOCK="/tmp/corsairctl-waybar.lock"
MAX_AGE=10
FALLBACK='{"text":"󰋋 ?","tooltip":"HS80: nicht erreichbar","class":"offline","percentage":0}'
# Cache frisch genug?
if [[ -f "$CACHE" ]]; then
# Cache frisch genug? Direkt ausgeben.
if [[ -f "$CACHE" ]] && [[ -s "$CACHE" ]]; then
age=$(( $(date +%s) - $(stat -c %Y "$CACHE") ))
if (( age < MAX_AGE )); then
cat "$CACHE"
@ -15,9 +16,14 @@ if [[ -f "$CACHE" ]]; then
fi
fi
# Lock holen und aktualisieren
# Lock holen, abfragen, cachen.
(
flock -n 9 || { [[ -f "$CACHE" ]] && cat "$CACHE"; exit 0; }
corsairctl json > "$CACHE" 2>/dev/null
cat "$CACHE"
flock -w 5 9 || { cat "$CACHE" 2>/dev/null || echo "$FALLBACK"; exit 0; }
if corsairctl json > "${CACHE}.tmp" 2>/dev/null; then
mv "${CACHE}.tmp" "$CACHE"
cat "$CACHE"
else
rm -f "${CACHE}.tmp"
echo "$FALLBACK"
fi
) 9>"$LOCK"