diff --git a/.config/waybar/scripts/alhp.sh b/.config/waybar/scripts/alhp.sh index 4020d20..ba035e0 100755 --- a/.config/waybar/scripts/alhp.sh +++ b/.config/waybar/scripts/alhp.sh @@ -2,35 +2,45 @@ set -euo pipefail IFS=$'\n\t' -ALHP_OUTPUT=$(alhp.utils -j) -total=$(jq -r '.total' <<<"$ALHP_OUTPUT") -mirror_stale=$(jq -r '.mirror_out_of_date' <<<"$ALHP_OUTPUT") - # defaults text="" tooltip='All good' class='good' -# safe array even if packages is null -readarray -t packages < <( - jq -r '.packages // [] | .[]' <<<"$ALHP_OUTPUT" - ) +# Check if alhp.utils command exists, if not consider it as down +if ! command -v alhp.utils &> /dev/null; then + tooltip="Service unavailable" + text="" + class="down" +else + ALHP_OUTPUT=$(alhp.utils -j) + mirror_stale=$(jq -r '.mirror_out_of_date' <<<"$ALHP_OUTPUT") -# 1) Mirror stale? highest priority -if [[ "$mirror_stale" == "true" ]]; then - class="stale" - tooltip="Mirror is out of date" -# 2) Any pending PKGBUILDs? -elif (( total > 0 )); then - class="bad" - text="$total" - tooltip=$(printf "%s\n" "${packages[@]}") + total=$(jq -r '.total' <<<"$ALHP_OUTPUT") + mirror_stale=$(jq -r '.mirror_out_of_date' <<<"$ALHP_OUTPUT") + + # safe array even if packages is null + readarray -t packages < <( + jq -r '.packages // [] | .[]' <<<"$ALHP_OUTPUT" + ) + + # 1) Mirror stale? highest priority + if [[ "$mirror_stale" == "true" ]]; then + class="stale" + tooltip="Mirror is out of date" + # 2) Any pending PKGBUILDs? + elif (( total > 0 )); then + class="bad" + text="$total" + tooltip=$(printf "%s\n" "${packages[@]}") + fi fi case "$class" in good) icon="";; stale) icon="󰏖";; bad) icon="󰏗";; + down) icon="x";; esac # Emit compact JSON for Statusbar diff --git a/.config/waybar/style.css##hostname.cn-arch b/.config/waybar/style.css##hostname.cn-arch index f6904f8..58ad617 100644 --- a/.config/waybar/style.css##hostname.cn-arch +++ b/.config/waybar/style.css##hostname.cn-arch @@ -194,11 +194,14 @@ tooltip label { padding-right: 5px; } #custom-alhp.good { - border-bottom: 1px solid greenyellow; + border-bottom: 1px solid #adff2f; } #custom-alhp.stale { - border-bottom: 1px solid yellow; + border-bottom: 1px solid #f6ac00; } #custom-alhp.bad { - border-bottom: 1px solid orangered; + border-bottom: 1px solid #ff4500; +} +#custom-alhp.down { + border-bottom: 1px solid #800000; } diff --git a/.config/waybar/style.css##hostname.cn-mate b/.config/waybar/style.css##hostname.cn-mate index 2a7f6ce..bee802b 100644 --- a/.config/waybar/style.css##hostname.cn-mate +++ b/.config/waybar/style.css##hostname.cn-mate @@ -191,15 +191,18 @@ tooltip label{ } #custom-alhp { - padding-left: 5px; - padding-right: 5px; + padding-left: 5px; + padding-right: 5px; } #custom-alhp.good { - border-bottom: 1px solid greenyellow; + border-bottom: 1px solid #adff2f; } #custom-alhp.stale { - border-bottom: 1px solid yellow; + border-bottom: 1px solid #f6ac00; } #custom-alhp.bad { - border-bottom: 1px solid orangered; + border-bottom: 1px solid #ff4500; +} +#custom-alhp.down { + border-bottom: 1px solid #800000; }