Files
bananarchy/overlay/rootfs/usr/bin/sxmo_notifs.sh
T
Luxferre 2ae4ef34a2 Implement 0010 RPM/L2/WCD/UART deep-standby, Adreno 304 ICC/SMMU fixes, and C11 autostart daemons
- patches/kernel/0010-msm8909-rpm-lpm-bimc-wcd-ldo-uart.patch and device DTS/DTB files (nokia-{argon,beatles,beatles-cover,coconut,sparkler,leo}): vMPM APSS RPM sleep, L2 SAW2 collapse, WCD-digital runtime PM, PM8909 LDO seeding, ttyMSM0 disable, dynamic msm_gpu gfx-mem BIMC interconnect scaling (mas_oxili), and qcom_iommu context restore + atomic TLB flush on resume.
- Replace Python/shell autostart loops with compiled C11 ARM ELF daemons (bananarchy-dsds, bananarchy-modemmonitor, bananarchy-soundmonitor, bananarchy-notifmonitor, bananarchy-run-aligned, bananarchy-session-loop) plus scripts/test-dsds-daemon.py.
- Update scripts/check-rebuild.sh, CHANGELOG.md, BATTERY-OPTIMIZATION-ANALYSIS.md, MANUAL.md, README.md, and AGENTS.md with verified a1114 (carbonara) image/archive pins and guards.
2026-11-13 18:23:14 +02:00

212 lines
4.8 KiB
Bash
Executable File

#!/bin/sh
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2022 Sxmo Contributors
# include common definitions
# shellcheck source=scripts/core/sxmo_common.sh
. sxmo_common.sh
# shellcheck source=configs/default_hooks/sxmo_hook_icons.sh
. sxmo_hook_icons.sh
SXMO_NOTIFDIR="${SXMO_NOTIFDIR:-${XDG_DATA_HOME:-$HOME/.local/share}/sxmo/notifications}"
[ -z "$SXMO_NOTIFDIR" ] || [ "$SXMO_NOTIFDIR" = "/" ] && SXMO_NOTIFDIR="$HOME/.local/share/sxmo/notifications"
_clear_notif_group() {
find "$SXMO_NOTIFDIR" -type f 2>/dev/null | while read -r file; do
if [ -f "$file" ] && awk NR==1 "$file" 2>/dev/null | grep -lxq "$1"; then
rm -f "$file"
fi
done
}
clear_all() {
rm -f "$SXMO_NOTIFDIR"/* 2>/dev/null || true
dunstctl close-all >/dev/null 2>&1 || true
dunstctl history-clear >/dev/null 2>&1 || true
killall -q dunstify >/dev/null 2>&1 || true
sxmo_hook_statusbar.sh notifications >/dev/null 2>&1 || true
}
_handle_new_notif_file() {
file="$1"
mode="$2"
case "${file##*/}" in
.*) return 0 ;;
esac
[ -f "$file" ] || return 0
if [ "$(wc -l < "$file" 2>/dev/null || echo 0)" -lt 3 ]; then
sxmo_log "Invalid notification file $file found, deleting!"
rm -f "$file"
return 0
fi
if [ "$mode" != "boot" ]; then
sxmo_hook_notification.sh "$file" &
fi
group="$(awk NR==1 "$file" 2>/dev/null)"
action="$(awk NR==2 "$file" 2>/dev/null)"
msg="$(tail -n+3 "$file" 2>/dev/null | cut -c1-70)"
(
case "$(dunstify --action="default,Open" "$msg" 2>/dev/null)" in
"2")
;;
"default")
_clear_notif_group "$group"
sxmo_hook_statusbar.sh notifications >/dev/null 2>&1 || true
if [ -n "$action" ] && [ "$action" != "none" ]; then
setsid -f sh -c "$action" > /dev/null 2>&1
fi
;;
esac
) &
}
_notifications_hook() {
_cnt=0
for _nf in "$SXMO_NOTIFDIR"/*; do
[ -f "$_nf" ] && _cnt=$((_cnt + 1))
done
sxmo_hook_notifications.sh "$_cnt"
}
monitor() {
exec /usr/bin/bananarchy-notifmonitor
}
_menu_lines() {
find "$SXMO_NOTIFDIR" -type f 2>/dev/null | while read -r file; do
[ -f "$file" ] || continue
msg="$(tail -n+3 "$file" 2>/dev/null | tr "\n^" " ")"
hrandmin="$(stat -c %y "$file" 2>/dev/null | grep -oE '[0-9]{2}:[0-9]{2}' | head -n1)"
cat <<EOF
$hrandmin $msg^$file
EOF
done
}
menu() {
choices="$(cat <<EOF
$icon_del Clear Notifications
$(_menu_lines)
$icon_bel Notification Sound
$icon_cls Close Menu
EOF
)"
picked="$(
printf "%b" "$choices" |
cut -d^ -f1 |
sxmo_dmenu.sh -i -p "Notifs"
)"
case "$picked" in
"$icon_cls Close Menu"|"")
exit
;;
"$icon_del Clear Notifications")
clear_all
exit
;;
"$icon_bel Notification Sound")
setsid -f xringtones --notif >/dev/null 2>&1
exit
;;
*)
file="$(
printf "%b" "$choices" |
grep -F "$picked" |
cut -d^ -f2 |
head -n1
)"
if [ -n "$file" ] && [ -f "$file" ]; then
group="$(awk NR==1 "$file" 2>/dev/null)"
action="$(awk NR==2 "$file" 2>/dev/null)"
_clear_notif_group "$group"
rm -f "$file" 2>/dev/null || true
dunstctl close-all >/dev/null 2>&1 || true
sxmo_hook_statusbar.sh notifications >/dev/null 2>&1 || true
if [ -n "$action" ] && [ "$action" != "none" ]; then
setsid -f sh -c "$action" > /dev/null 2>&1
fi
fi
;;
esac
}
new() {
while : ; do
case "$1" in
-i)
id="$2"
shift 2
;;
-g)
group="$2"
shift 2
;;
*)
break
;;
esac
done
if [ "$#" -lt 2 ]; then
usage
exit 1
fi
if [ -z "$id" ]; then
id="$(tr -dc 'a-zA-Z0-9' < /dev/urandom 2>/dev/null | head -c 10)"
fi
if [ -z "$group" ]; then
group="$(tr -dc 'a-zA-Z0-9' < /dev/urandom 2>/dev/null | head -c 10)"
fi
action="$1"
msg="$2"
mkdir -p "$SXMO_NOTIFDIR"
tmp_notif="$SXMO_NOTIFDIR/.tmp.$id.$$"
printf "%s\n%s\n%b\n" "$group" "$action" "$msg" > "$tmp_notif"
mv -f "$tmp_notif" "$SXMO_NOTIFDIR/$id"
if ! pidof -s bananarchy-notifmonitor >/dev/null 2>&1 && \
! pgrep -f "sxmo_notifs.sh monitor" >/dev/null 2>&1; then
sxmo_hook_notification.sh "$SXMO_NOTIFDIR/$id" &
fi
sxmo_hook_statusbar.sh notifications
}
usage() {
cat <<EOF
$(basename "$0"): manage sxmo notifications
Subcommands:
monitor
Watch for new notification, dispatch libnotify events, handle actions
menu
Open a menu to dismiss notifications
clear
Clear all notifications and close active Dunst popups
new [-i id] [-g group] <action> <message...>
Register a new notification
EOF
}
cmd="$1"
shift 2>/dev/null || true
case "$cmd" in
monitor) monitor "$@" ;;
menu) menu "$@" ;;
clear) clear_all ;;
new) new "$@" ;;
*)
usage
exit 1
;;
esac