Fix SIM2 QMI UIM provisioning, auto-enable ModemManager, PIN auto-prompt, call audio, and Dunst clearing

This commit is contained in:
Luxferre
2026-10-25 11:31:41 +02:00
parent 9b712dcbca
commit b56f310f21
41 changed files with 1193 additions and 352 deletions
+155 -135
View File
@@ -12,189 +12,209 @@ SXMO_NOTIFDIR="${SXMO_NOTIFDIR:-${XDG_DATA_HOME:-$HOME/.local/share}/sxmo/notifi
[ -z "$SXMO_NOTIFDIR" ] || [ "$SXMO_NOTIFDIR" = "/" ] && SXMO_NOTIFDIR="$HOME/.local/share/sxmo/notifications"
_clear_notif_group() {
find "$SXMO_NOTIFDIR" -type f | while read -r file; do
if awk NR==1 "$file" | grep -lxq "$1"; then
rm "$file"
fi
done
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
}
_handle_new_notif_file(){
file="$1"
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
pkill -x dunstify >/dev/null 2>&1 || true
sxmo_hook_statusbar.sh notifications >/dev/null 2>&1 || true
}
if [ "$(wc -l "$file" | cut -d' ' -f1)" -lt 3 ]; then
sxmo_log "Invalid notification file $file found, deleting!"
rm -f "$file"
return
fi
_handle_new_notif_file() {
file="$1"
[ -f "$file" ] || return 0
sxmo_hook_notification.sh "$file" &
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
group="$(awk NR==1 "$file")"
action="$(awk NR==2 "$file")"
msg="$(tail -n+3 "$file" | cut -c1-70)"
sxmo_hook_notification.sh "$file" &
case "$(dunstify --action="default,Open" "$msg")" in
"2")
#
# _clear_notif_group "$group"
#
;;
"default")
_clear_notif_group "$group"
setsid -f sh -c "$action" > /dev/null 2>&1
;;
esac
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"
_cnt=0
for _nf in "$SXMO_NOTIFDIR"/*; do
[ -f "$_nf" ] && _cnt=$((_cnt + 1))
done
sxmo_hook_notifications.sh "$_cnt"
}
monitor() {
mkdir -p "$SXMO_NOTIFDIR"
mkdir -p "$SXMO_NOTIFDIR"
find "$SXMO_NOTIFDIR" -type f | while read -r file; do
_handle_new_notif_file "$file"
done
find "$SXMO_NOTIFDIR" -type f 2>/dev/null | while read -r file; do
_handle_new_notif_file "$file"
done
_notifications_hook
_notifications_hook
fifo="$(mktemp -u)"
mkfifo "$fifo"
inotifywait -mq -e attrib,move,delete "$SXMO_NOTIFDIR" >> "$fifo" &
inotif_pid=$!
fifo="$(mktemp -u)"
mkfifo "$fifo"
inotifywait -mq -e close_write,moved_to,delete "$SXMO_NOTIFDIR" >> "$fifo" &
inotif_pid=$!
finish() {
kill "$inotif_pid"
rm "$fifo"
exit
}
trap 'finish' TERM INT EXIT
finish() {
kill "$inotif_pid" 2>/dev/null || true
rm -f "$fifo"
exit
}
trap 'finish' TERM INT EXIT
while read -r notif_folder notif_type notif_file; do
if echo "$notif_type" | grep -qE "CREATE|MOVED_TO|ATTRIB"; then
_handle_new_notif_file "$notif_folder$notif_file"
fi
_notifications_hook
done < "$fifo"
while read -r notif_folder notif_type notif_file; do
if echo "$notif_type" | grep -qE "CLOSE_WRITE|MOVED_TO"; then
_handle_new_notif_file "$notif_folder$notif_file"
fi
_notifications_hook
done < "$fifo"
wait "$inotif_pid"
wait "$inotif_pid"
}
_menu_lines() {
find "$SXMO_NOTIFDIR" -type f | while read -r file; do
msg="$(tail -n+3 "$file" | tr "\n^" " ")"
hrandmin="$(stat --printf %y "$file" | grep -oE '[0-9]{2}:[0-9]{2}')"
cat <<EOF
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
done
}
menu() {
choices="$(cat <<EOF
$icon_cls Close Menu
choices="$(cat <<EOF
$icon_del Clear Notifications
$(_menu_lines)
$icon_cls Close Menu
EOF
)"
)"
picked="$(
printf "%b" "$choices" |
cut -d^ -f1 |
sxmo_dmenu.sh -i -p "Notifs"
)"
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")
rm "$SXMO_NOTIFDIR"/*
# we must update statusbar here because this function depends
# on number of files in $SXMO_NOTIFDIR
sxmo_hook_statusbar.sh notifications
exit
;;
*)
file="$(
printf "%b" "$choices" |
grep -F "$picked" |
cut -d^ -f2
)"
group="$(awk NR==1 "$file")"
action="$(awk NR==2 "$file")"
_clear_notif_group "$group"
setsid -f sh -c "$action" > /dev/null 2>&1
;;
esac
case "$picked" in
"$icon_cls Close Menu"|"")
exit
;;
"$icon_del Clear Notifications")
clear_all
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
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 [ "$#" -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
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"
action="$1"
msg="$2"
touch "$SXMO_NOTIFDIR/$id"
printf "%s\n%s\n%b\n" "$group" "$action" "$msg" > "$SXMO_NOTIFDIR/$id"
mkdir -p "$SXMO_NOTIFDIR"
printf "%s\n%s\n%b\n" "$group" "$action" "$msg" > "$SXMO_NOTIFDIR/$id"
sxmo_hook_statusbar.sh notifications
sxmo_hook_statusbar.sh notifications
}
usage() {
cat <<EOF
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
new [-i id] [-g group] <action> <message...>
Register a new notification
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
shift 2>/dev/null || true
case "$cmd" in
monitor) monitor "$@";;
menu) menu "$@";;
new) new "$@";;
*)
usage
exit 1
;;
monitor) monitor "$@" ;;
menu) menu "$@" ;;
clear) clear_all ;;
new) new "$@" ;;
*)
usage
exit 1
;;
esac