Waybar: Add package update count module + pacman hook.

This commit is contained in:
Viyurz 2024-02-12 09:36:45 +01:00
parent e0fd2ddee9
commit 66cfa30818
No known key found for this signature in database
4 changed files with 73 additions and 0 deletions

View file

@ -6,6 +6,7 @@
"hyprland/workspaces", "hyprland/workspaces",
"tray", "tray",
"custom/dnd-toggle", "custom/dnd-toggle",
"custom/pkg-update-count",
"network", "network",
"bluetooth", "bluetooth",
"pulseaudio#output", "pulseaudio#output",
@ -34,6 +35,20 @@
// "icon-size": 21, // "icon-size": 21,
"spacing": 8 "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": { "network": {
// "interface": "wlp2*", // (Optional) To force the use of this interface // "interface": "wlp2*", // (Optional) To force the use of this interface
"interval": 5, "interval": 5,

View file

@ -47,6 +47,7 @@
#button, #button,
#tray, #tray,
#custom-pkg-update-count,
#network, #network,
#bluetooth, #bluetooth,
#pulseaudio, #pulseaudio,
@ -84,6 +85,7 @@
color: @accent1; color: @accent1;
} }
#custom-pkg-update-count,
#network, #network,
#bluetooth, #bluetooth,
#mpris, #mpris,
@ -93,6 +95,7 @@
color: @accent2; color: @accent2;
} }
#custom-pkg-update-count.no-update,
#pulseaudio.output.muted, #pulseaudio.output.muted,
#pulseaudio.input.source-muted, #pulseaudio.input.source-muted,
#custom-dnd-toggle.dnd-enabled { #custom-dnd-toggle.dnd-enabled {
@ -104,6 +107,10 @@
color: @disabled2; color: @disabled2;
} }
#custom-pkg-update-count.error {
color: @bad;
}
#battery.charging { #battery.charging {
background-color: alpha(@good, 0.33); background-color: alpha(@good, 0.33);
} }

View file

@ -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

View file

@ -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