From 5b05bb9c2c366ce95fdb4fbd08ac1ad54d79950e Mon Sep 17 00:00:00 2001 From: Jonathan Hodgson Date: Mon, 5 Apr 2021 10:23:39 +0100 Subject: [PATCH] Changes the sms log file so that new messages can be counted The log now contains @READ@ where @ is a null byte where new and old messages diverge. This means that new sms's can be more easily counted This, as well as a count for missed calls, has been added to the phoneStatus notification --- bin/.bin/modem/checkSMS | 2 ++ bin/.bin/notifications/phoneStatus | 25 +++++++++++++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/bin/.bin/modem/checkSMS b/bin/.bin/modem/checkSMS index dcb48cbf..4412807e 100755 --- a/bin/.bin/modem/checkSMS +++ b/bin/.bin/modem/checkSMS @@ -61,6 +61,8 @@ echo "$ids" | while read -r id; do log="$SMS_DIR/$number/sms.log" + [ ! -f "$log" ] && printf '\00READ\00' >> "$log" + # Store the message in the log file echo "RECIEVED" echo "SENDER: $number" >> $log diff --git a/bin/.bin/notifications/phoneStatus b/bin/.bin/notifications/phoneStatus index 1dc8d2ec..97037fed 100755 --- a/bin/.bin/notifications/phoneStatus +++ b/bin/.bin/notifications/phoneStatus @@ -1,10 +1,31 @@ #!/usr/bin/env bash +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" +source "$DIR/../modem/common" + battery="$(cat /sys/class/power_supply/axp20x-battery/capacity)" batteryStatus="$(cat /sys/class/power_supply/axp20x-battery/status)" [ "$batteryStatus" = "Charging" ] && batteryIcon="🔌" || batteryIcon="🔋" - +missedCallsNo="$(cat "$CALL_DIR/missed-calls" | wc -l )" time="$(date "+%H:%M")" -notify-send "$(hostname)" "$batteryIcon ${battery}%\nTime $time" +newTexts=0 +for i in "$SMS_DIR"/*/sms.log; do + echo "$i" + count="$(sed -n '/\x0READ\x0/,$ p' "$i" | sed '1d' | + sed -n 's/\x0/-/p' | wc -l)" + echo "$count" + newTexts=$(( newTexts + count )) +done + + + +notification=" +$batteryIcon ${battery}% +Time $time +$( [ "$missedCallsNo" -gt 0 ] && echo "$missedCallsNo Missed Calls" ) +$( [ "$newTexts" -gt 0 ] && echo "$newTexts New Texts" )" + +notification="$( echo "$notification" | sed '/^$/d' )" +notify-send "$(hostname)" "$notification"