[eww] Add packages updates
This commit is contained in:
parent
d65c8aad42
commit
866c052c26
3 changed files with 95 additions and 6 deletions
|
@ -1,4 +1,4 @@
|
||||||
; Brightness
|
; Brightness
|
||||||
(deflisten brightness :initial "128" "while :; do cat /sys/class/backlight/amdgpu_bl1/brightness; sleep 0.1; done")
|
(deflisten brightness :initial "128" "while :; do cat /sys/class/backlight/amdgpu_bl1/brightness; sleep 0.1; done")
|
||||||
(defvar brightness-icons '["", "", "", "", "", "", "", "", "", "", "", "", "", "", ""]')
|
(defvar brightness-icons '["", "", "", "", "", "", "", "", "", "", "", "", "", "", ""]')
|
||||||
(defvar brightness-slide false)
|
(defvar brightness-slide false)
|
||||||
|
@ -8,10 +8,16 @@
|
||||||
|
|
||||||
; DateTime
|
; DateTime
|
||||||
(defpoll datetime :interval "1s" "date +'%a %e %b %X'")
|
(defpoll datetime :interval "1s" "date +'%a %e %b %X'")
|
||||||
(defpoll month :interval "1m" :initial "0" "date +'%m'")
|
(defpoll month :interval "1m" :initial "1" "date +'%m'")
|
||||||
(defpoll day :interval "1m" :initial "0" "date +'%d'")
|
(defpoll day :interval "1m" :initial "1" "date +'%d'")
|
||||||
(defpoll year :interval "1m" :initial "0" "date +'%Y'")
|
(defpoll year :interval "1m" :initial "0" "date +'%Y'")
|
||||||
|
|
||||||
|
; Notifications status
|
||||||
|
(deflisten nf-enabled :initial "true" "while :; do makoctl mode | grep -q dnd && echo true || echo false; sleep 0.1; done")
|
||||||
|
|
||||||
|
; Packages updates
|
||||||
|
(deflisten packages-updates :initial '{"count": "-", "class": " "}' "~/.config/eww/scripts/pkg-updates.sh")
|
||||||
|
|
||||||
; Window Title
|
; Window Title
|
||||||
(deflisten window-title "~/.config/eww/scripts/get-window-title.sh")
|
(deflisten window-title "~/.config/eww/scripts/get-window-title.sh")
|
||||||
|
|
||||||
|
@ -19,9 +25,6 @@
|
||||||
(deflisten workspaces :initial "[]" "~/.config/eww/scripts/get-workspaces.sh")
|
(deflisten workspaces :initial "[]" "~/.config/eww/scripts/get-workspaces.sh")
|
||||||
(deflisten active-workspace "~/.config/eww/scripts/get-active-workspace.sh")
|
(deflisten active-workspace "~/.config/eww/scripts/get-active-workspace.sh")
|
||||||
|
|
||||||
; Notifications status
|
|
||||||
(deflisten nf-enabled :initial "true" "while :; do makoctl mode | grep -q dnd && echo true || echo false; sleep 0.1; done")
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
; Widgets
|
; Widgets
|
||||||
|
@ -34,6 +37,7 @@
|
||||||
:class "systray"
|
:class "systray"
|
||||||
)
|
)
|
||||||
(nf-state)
|
(nf-state)
|
||||||
|
(packages-updates)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -58,6 +62,14 @@
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
(defwidget packages-updates []
|
||||||
|
(label :text " ${packages-updates.count}"
|
||||||
|
:class "${packages-updates.class}"
|
||||||
|
:tooltip "${packages-updates.tooltip}"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
(defwidget bar-middle []
|
(defwidget bar-middle []
|
||||||
(label :limit-width 2
|
(label :limit-width 2
|
||||||
:text "${window-title}"
|
:text "${window-title}"
|
||||||
|
|
10
.config/eww/refresh-pkg-updates.hook
Normal file
10
.config/eww/refresh-pkg-updates.hook
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
# Copy to /etc/pacman.d/hooks/
|
||||||
|
[Trigger]
|
||||||
|
Operation = Upgrade
|
||||||
|
Operation = Remove
|
||||||
|
Type = Package
|
||||||
|
Target = *
|
||||||
|
|
||||||
|
[Action]
|
||||||
|
When = PostTransaction
|
||||||
|
Exec = /bin/pkill -SIGUSR1 -u 1000 pkg-updates.sh
|
67
.config/eww/scripts/pkg-updates.sh
Executable file
67
.config/eww/scripts/pkg-updates.sh
Executable file
|
@ -0,0 +1,67 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Time in seconds between each check
|
||||||
|
interval=3600
|
||||||
|
# Number of updates displayed in tooltip
|
||||||
|
max_shown=25
|
||||||
|
|
||||||
|
|
||||||
|
function check {
|
||||||
|
# Initiate variables
|
||||||
|
declare -i retry_count=0
|
||||||
|
declare -i max_retries=5
|
||||||
|
declare -i retry_delay=30
|
||||||
|
declare -i success=0
|
||||||
|
|
||||||
|
# Retry until success or retry count reaches max_retries
|
||||||
|
while [[ $retry_count -le $max_retries && $success -ne 1 ]]; do
|
||||||
|
cmd_res="$(checkupdates 2>&1)"
|
||||||
|
case $? in
|
||||||
|
# Update(s) available
|
||||||
|
0)
|
||||||
|
success=1
|
||||||
|
count=$(echo "$cmd_res" | wc -l)
|
||||||
|
tooltip="$(echo "$cmd_res" | head -n "$max_shown" | sed -z 's/\n/\\n/g' | sed 's/\\n$//')"
|
||||||
|
if [[ $count -gt $max_shown ]]; then
|
||||||
|
tooltip="$tooltip\n[..] +$((count - max_shown))"
|
||||||
|
fi
|
||||||
|
class=" "
|
||||||
|
;;
|
||||||
|
|
||||||
|
# No update available
|
||||||
|
2)
|
||||||
|
success=1
|
||||||
|
count=0
|
||||||
|
tooltip="No update available."
|
||||||
|
class="disabled"
|
||||||
|
;;
|
||||||
|
|
||||||
|
*)
|
||||||
|
retry_count+=1
|
||||||
|
count=""
|
||||||
|
tooltip="$(echo "$cmd_res" | sed -z 's/\n/\\n/g' | sed 's/\\n$//')"
|
||||||
|
class="error"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
# Show time of check
|
||||||
|
time="$(date '+%H:%M:%S')"
|
||||||
|
tooltip="$tooltip\n\nLatest check: $time"
|
||||||
|
|
||||||
|
cat <<- EOF
|
||||||
|
{"count": "$count", "tooltip": "$tooltip", "class": "$class"}
|
||||||
|
EOF
|
||||||
|
|
||||||
|
[[ $success -ne 1 ]] && sleep $retry_delay
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
declare -i sleep_pid
|
||||||
|
|
||||||
|
while :; do
|
||||||
|
check
|
||||||
|
sleep $interval &
|
||||||
|
sleep_pid=$!
|
||||||
|
trap "kill $sleep_pid" USR1
|
||||||
|
wait $sleep_pid
|
||||||
|
done
|
Loading…
Reference in a new issue