diff --git a/.config/waybar/config b/.config/waybar/config index 76cbac3..36220d4 100644 --- a/.config/waybar/config +++ b/.config/waybar/config @@ -6,6 +6,7 @@ "hyprland/workspaces", "tray", "custom/dnd-toggle", + "custom/pkg-update-count", "network", "bluetooth", "pulseaudio#output", @@ -34,6 +35,20 @@ // "icon-size": 21, "spacing": 8 }, + "custom/pkg-update-count": { + "exec": "$HOME/.scripts/waybar-pkg-update-count.sh", + "interval": "once", + "on-click": "$HOME/.scripts/waybar-pkg-update-count.sh", + "signal": 3, + "tooltip": false, + "return-type": "json", + "format": "{icon} {}", + "format-icons": { + "error": "󰏖", + "no-update": "󰏖", + "update-available": "󰏖" + } + }, "network": { // "interface": "wlp2*", // (Optional) To force the use of this interface "interval": 5, diff --git a/.config/waybar/style.css b/.config/waybar/style.css index c6d8a49..c2ba05f 100644 --- a/.config/waybar/style.css +++ b/.config/waybar/style.css @@ -47,6 +47,7 @@ #button, #tray, +#custom-pkg-update-count, #network, #bluetooth, #pulseaudio, @@ -84,6 +85,7 @@ color: @accent1; } +#custom-pkg-update-count, #network, #bluetooth, #mpris, @@ -93,6 +95,7 @@ color: @accent2; } +#custom-pkg-update-count.no-update, #pulseaudio.output.muted, #pulseaudio.input.source-muted, #custom-dnd-toggle.dnd-enabled { @@ -104,6 +107,10 @@ color: @disabled2; } +#custom-pkg-update-count.error { + color: @bad; +} + #battery.charging { background-color: alpha(@good, 0.33); } diff --git a/.scripts/refresh-waybar-pkg-update-count.hook b/.scripts/refresh-waybar-pkg-update-count.hook new file mode 100644 index 0000000..e525c91 --- /dev/null +++ b/.scripts/refresh-waybar-pkg-update-count.hook @@ -0,0 +1,10 @@ +# Refresh the package update count Waybar module +[Trigger] +Operation = Upgrade +Operation = Remove +Type = Package +Target = * + +[Action] +When = PostTransaction +Exec = pkill -SIGRTMIN+3 -u 1000 waybar diff --git a/.scripts/waybar-pkg-update-count.sh b/.scripts/waybar-pkg-update-count.sh new file mode 100755 index 0000000..37aa473 --- /dev/null +++ b/.scripts/waybar-pkg-update-count.sh @@ -0,0 +1,41 @@ +#!/bin/bash -x + + +# Initiate variables +retry_count=0 +max_retries=3 +retry_delay=15 +success=0 + + +# Retry until success or retry count reaches max_retries +while [[ $retry_count -le $max_retries && $success -ne 1 ]]; do + update_list="$(checkupdates)" + case $? in + # Update(s) available + 0) + success=1 + output=$(echo "$update_list" | wc -l) + class="update-available" + ;; + + # No update available + 2) + success=1 + output=0 + class="no-update" + ;; + + *) + sleep $retry_delay + retry_count+=1 + output="" + class="error" + ;; + esac +done + + +cat << EOF +{"text": "$output", "alt": "$class", "tooltip": "$output", "class": "$class"} +EOF