diff --git a/README.md b/README.md index f1c7460..9804407 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/defaults/bin/moonarch-waybar-updates b/defaults/bin/moonarch-waybar-updates new file mode 100755 index 0000000..9169417 --- /dev/null +++ b/defaults/bin/moonarch-waybar-updates @@ -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" diff --git a/defaults/xdg/waybar/config b/defaults/xdg/waybar/config index 78b6de7..7e71b58 100644 --- a/defaults/xdg/waybar/config +++ b/defaults/xdg/waybar/config @@ -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,