feat: add waybar module for package update notifications
All checks were successful
Update PKGBUILD version / update-pkgver (push) Successful in 3s
All checks were successful
Update PKGBUILD version / update-pkgver (push) Successful in 3s
Add moonarch-waybar-updates script that checks for available updates from both official repos (checkupdates) and AUR (paru -Qua). Uses a cache mechanism to avoid excessive mirror hits while still detecting freshly installed updates within 60 seconds.
This commit is contained in:
parent
46ba8365db
commit
8ddbb23851
@ -132,6 +132,7 @@ defaults/
|
||||
moonarch-waybar-gpustat Waybar module: GPU utilization
|
||||
moonarch-waybar-hidpp Waybar module: Logitech HID++ device battery
|
||||
moonarch-waybar-batsaver Waybar module: battery conservation mode indicator
|
||||
moonarch-waybar-updates Waybar module: package update checker (repo + AUR)
|
||||
moonarch-batsaver-toggle Toggle battery charge limit (80% ↔ 100%)
|
||||
|
||||
shell/zshrc Zsh config: prompt, aliases, FZF, completion
|
||||
|
||||
68
defaults/bin/moonarch-waybar-updates
Executable file
68
defaults/bin/moonarch-waybar-updates
Executable file
@ -0,0 +1,68 @@
|
||||
#!/usr/bin/bash
|
||||
# ABOUTME: Waybar module that checks for available package updates with caching.
|
||||
# ABOUTME: Combines pacman repo updates (checkupdates) and AUR updates (paru -Qua).
|
||||
|
||||
CACHE_DIR="${XDG_CACHE_HOME:-$HOME/.cache}/moonarch"
|
||||
CACHE_FILE="$CACHE_DIR/waybar-updates"
|
||||
PACMAN_DB="/var/lib/pacman/local"
|
||||
MAX_AGE=3600
|
||||
|
||||
mkdir -p "$CACHE_DIR"
|
||||
|
||||
needs_refresh() {
|
||||
# No cache yet
|
||||
[[ ! -f "$CACHE_FILE" ]] && return 0
|
||||
|
||||
# Pacman DB changed since last check (update was installed)
|
||||
[[ "$PACMAN_DB" -nt "$CACHE_FILE" ]] && return 0
|
||||
|
||||
# Cache older than MAX_AGE
|
||||
local age=$(( $(date +%s) - $(stat -c %Y "$CACHE_FILE") ))
|
||||
[[ "$age" -ge "$MAX_AGE" ]] && return 0
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
if needs_refresh; then
|
||||
repo_updates=$(checkupdates 2>/dev/null)
|
||||
repo_count=0
|
||||
if [[ -n "$repo_updates" ]]; then
|
||||
repo_count=$(echo "$repo_updates" | wc -l)
|
||||
fi
|
||||
|
||||
aur_updates=""
|
||||
aur_count=0
|
||||
if command -v paru &>/dev/null; then
|
||||
aur_updates=$(paru -Qua 2>/dev/null)
|
||||
if [[ -n "$aur_updates" ]]; then
|
||||
aur_count=$(echo "$aur_updates" | wc -l)
|
||||
fi
|
||||
fi
|
||||
|
||||
total=$((repo_count + aur_count))
|
||||
|
||||
if [[ "$total" -eq 0 ]]; then
|
||||
echo "" > "$CACHE_FILE"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Build tooltip with package lists
|
||||
tooltip=""
|
||||
if [[ -n "$repo_updates" ]]; then
|
||||
tooltip+="Repo ($repo_count):"$'\n'"$repo_updates"
|
||||
fi
|
||||
if [[ -n "$aur_updates" ]]; then
|
||||
[[ -n "$tooltip" ]] && tooltip+=$'\n\n'
|
||||
tooltip+="AUR ($aur_count):"$'\n'"$aur_updates"
|
||||
fi
|
||||
|
||||
jq --compact-output -n \
|
||||
--arg text "$total" \
|
||||
--arg alt "has-updates" \
|
||||
--arg tooltip "$tooltip" \
|
||||
--arg class "has-updates" \
|
||||
'{text: $text, alt: $alt, tooltip: $tooltip, class: $class}' > "$CACHE_FILE"
|
||||
fi
|
||||
|
||||
# Output cached result (empty cache = no updates = module hidden)
|
||||
cat "$CACHE_FILE"
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"__aboutme1": "Moonarch default waybar configuration for Niri.",
|
||||
"__aboutme2": "User overrides go in ~/.config/waybar/config",
|
||||
"__aboutme2": "Deployed to /etc/xdg/waybar/ by moonarch-git package.",
|
||||
"layer": "top",
|
||||
"margin-top": 0,
|
||||
"spacing": 5,
|
||||
@ -28,7 +28,7 @@
|
||||
"modules": [
|
||||
"custom/cpugov",
|
||||
"gamemode",
|
||||
//"custom/updates",
|
||||
"custom/updates",
|
||||
"idle_inhibitor",
|
||||
"custom/notification",
|
||||
"privacy"
|
||||
@ -205,9 +205,9 @@
|
||||
"has-updates": "",
|
||||
"updated": ""
|
||||
},
|
||||
"exec-if": "which waybar-module-pacman-updates",
|
||||
"exec": "waybar-module-pacman-updates",
|
||||
"on-click": "alacritty paru"
|
||||
"exec": "moonarch-waybar-updates",
|
||||
"interval": 60,
|
||||
"on-click": "foot paru"
|
||||
},
|
||||
"custom/notification": {
|
||||
"tooltip": true,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user