ark/users/modules/eww/scripts/notifications

82 lines
2.1 KiB
Plaintext
Raw Normal View History

2022-10-04 02:08:44 +03:00
#!/usr/bin/env bash
tmp=$XDG_CACHE_HOME/dunst-history.json
2022-10-22 23:54:44 +03:00
lock="$XDG_CACHE_HOME/dunst-toggle.lock"
lockinfo="$XDG_CACHE_HOME/dunst-lock-info"
touch $lockinfo
2022-10-04 02:08:44 +03:00
declare ids
export toggle_icon=""
get_ids() {
mapfile -t ids < <(dunstctl history | jq -r ".data[] | .[] | select(.appname.data != \"Spotify\") | .id.data")
}
get_notif() {
2022-10-22 23:54:44 +03:00
echo -n '(box :class "container" :orientation "v" :space-evenly false '
2022-10-04 02:08:44 +03:00
for id in "${ids[@]}"; do
mapfile -t n < <(jq -r ".data[] | .[] | select(.id.data == $id) | .appname.data, .summary.data, .body.data" "$tmp" | sed -r '/^\s*$/d' | sed -e 's/\%/ percent/g')
2022-10-22 23:54:44 +03:00
echo -n '(eventbox :onclick "dunstctl history-pop '"$id"' && dunstctl action 0 && dunstctl close" '
echo -n '(box :class "notification" :orientation "v" :width 300 :space-evenly false '
echo -n '(box :space-evenly false :spacing 10 '
echo -n '(label :halign "start" :xalign 0 :wrap true :class "summary" :text "'"${n[1]}"'")'
echo -n '(label :halign "end" :xalign 1 :wrap true :class "appname" :text "'"${n[0]}"'"))'
echo -n '(label :halign "start" :wrap true :class "body" :text "'"${n[2]}"'")))'
2022-10-04 02:08:44 +03:00
done
2022-10-22 23:54:44 +03:00
echo ')'
2022-10-04 02:08:44 +03:00
}
toggle() {
dunstctl set-paused toggle
if [ ! -f "$lock" ]; then
export toggle_icon=""
touch "$lock"
else
export toggle_icon=""
rm "$lock"
2022-10-22 23:54:44 +03:00
fi
echo "icon_change" > $lockinfo
2022-10-04 02:08:44 +03:00
}
clear() {
2022-10-22 23:54:44 +03:00
systemctl --user restart dunst
echo "icon_change" > $lockinfo
2022-10-04 02:08:44 +03:00
}
get_icon() {
if [ ${#ids[@]} -eq 0 ]; then
echo "󰆂"
else
echo "󰆄"
fi
}
if [ "$1" == "toggle" ]; then
toggle
dunstctl history > "$tmp"
elif [ "$1" == "clear" ]; then
clear
dunstctl history > "$tmp"
elif [ "$1" == "icons" ]; then
dunstctl history > "$tmp"
get_ids
echo '{"toggle_icon": "'"$toggle_icon"'", "icon": "'"$(get_icon)"'"}'
2022-10-22 23:54:44 +03:00
tail -f "$lockinfo" | while read -r; do
2022-10-04 02:08:44 +03:00
get_ids
echo '{"toggle_icon": "'"$toggle_icon"'", "icon": "'"$(get_icon)"'"}'
done
else
dunstctl history > "$tmp"
get_ids
get_notif
tail -f "$tmp" 2>/dev/null | rg --line-buffered "aa\{sv\}" | while read -r; do
get_ids
get_notif
done
fi