Rework the status bar

Goals of this patch :

- display the signal quality

I used a thermometer icon cause there is no available icon with a
filleable bar o_O

- display the currently used network technology (4g, 3g, etc...)

I used the mapping from:

https://gitlab.freedesktop.org/mobile-broadband/ModemManager/-/blob/master/include/ModemManager-enums.h#L220

Dylan also said:

Anything from POTS to GPRS = 2G
UMTS to EVDOB = 3G
LTE = 4G
5GNR = 5G

- display the modem infos when modemmonitor is disabled

We want to decorelate the modem monitor from the icon. We still want to
know easily if modem monitor is runing but we also want those modem
infos if not.

- simplify the modem state determination (no state file anymore)

The statusbar probe mmcli itself.

- fix the leading timer without call issue

This was caused by the "pgrep -f" command that was matching itself.
Using a simple "pgrep" looks good enough anyway.

- fix some sxmo_statusbar update spaming issues (vol control)

This one point took me a lot of time to findout a good solution. We want
the USR1 kill to be spamable without causing issue to the displayed bar.
We dont want mid rendered bar (half the icons).
We dont want empty bars (empty stdout line).

I use some variable to store pid, smart waits and a better trap function
to make it to works cleanly. Now we can spam statusbarupdate. Only the
last one will actually redraw the bar.

Signed-off-by: Stacy Harper <contact@stacyharper.net>
Signed-off-by: Maarten van Gompel <proycon@anaproy.nl>
This commit is contained in:
Stacy Harper 2021-09-12 09:34:55 +02:00 committed by Maarten van Gompel
parent 61451f6292
commit 55985a8f20
4 changed files with 132 additions and 107 deletions

View file

@ -12,8 +12,6 @@ err() {
}
gracefulexit() {
rm "$MODEMSTATEFILE"
sxmo_statusbarupdate.sh
sleep 1
echo "sxmo_modemmonitor: gracefully exiting (on signal or after error)">&2
kill -9 0
@ -223,17 +221,9 @@ checkfornewtexts() {
}
initialmodemstatus() {
touch "$MODEMSTATEFILE"
state=$(mmcli -m "$(modem_n)")
if echo "$state" | grep -q -E "^.*state:.*connected.*$"; then
echo connected > "$MODEMSTATEFILE"
elif echo "$state" | grep -q -E "^.*state:.*registered.*$"; then
echo registered > "$MODEMSTATEFILE"
elif echo "$state" | grep -q -E "^.*state:.*locked.*$"; then
echo locked > "$MODEMSTATEFILE"
if echo "$state" | grep -q -E "^.*state:.*locked.*$"; then
pidof unlocksim || sxmo_hooks.sh unlocksim &
else
echo unknown > "$MODEMSTATEFILE"
fi
}
@ -243,6 +233,7 @@ mainloop() {
checkforincomingcalls
checkfornewtexts
initialmodemstatus
# Monitor for incoming calls
dbus-monitor --system "interface='org.freedesktop.ModemManager1.Modem.Voice',type='signal',member='CallAdded'" | \
@ -262,11 +253,6 @@ mainloop() {
echo "$line" | grep -E "^signal" && checkforfinishedcalls
done &
#Monitor for modem state changes
# arg1 holds the new state: MM_MODEM_STATE_FAILED = -1, MM_MODEM_STATE_UNKNOWN = 0, ... MM_MODEM_STATE_REGISTERED=8, MM_MODEM_STATE_CONNECTED = 11
initialmodemstatus
sxmo_statusbarupdate.sh
dbus-monitor --system "interface='org.freedesktop.ModemManager1.Modem',type='signal',member='StateChanged'" | \
while read -r line; do
if echo "$line" | grep -E "^signal.*StateChanged"; then
@ -274,25 +260,14 @@ mainloop() {
read -r oldstate #unused but we need to read past it
read -r newstate
if echo "$newstate" | grep "int32 2"; then
echo locked > "$MODEMSTATEFILE"
pidof unlocksim || sxmo_hooks.sh unlocksim &
elif echo "$newstate" | grep "int32 8"; then
echo registered > "$MODEMSTATEFILE"
#if there is a PIN entry menu open, kill it:
# shellcheck disable=SC2009
ps aux | grep dmenu | grep PIN | gawk '{ print $1 }' | xargs kill
checkforfinishedcalls
checkforincomingcalls
checkfornewtexts
elif echo "$newstate" | grep "int32 11"; then
echo connected > "$MODEMSTATEFILE"
#3G/2G/4G available
elif echo "$newstate" | grep "int32 -1"; then
echo failed > "$MODEMSTATEFILE"
elif echo "$newstate" | grep "int32 3"; then
echo disabled > "$MODEMSTATEFILE"
else
echo unknown > "$MODEMSTATEFILE"
fi
sxmo_statusbarupdate.sh
fi
@ -316,7 +291,6 @@ mainloop() {
echo "sxmo_modemmonitor: modem not found, waiting for modem... (try #$TRIES)">&2
sleep 3
if [ "$TRIES" -eq 10 ]; then
echo failed > "$MODEMSTATEFILE"
echo "sxmo_modemmonitor: forcing modem restart">&2
sxmo_modemmonitortoggle.sh restart #will kill the modemmonitor too
break
@ -331,9 +305,6 @@ mainloop() {
wait
wait
wait
rm "$MODEMSTATEFILE" 2>/dev/null
sxmo_statusbarupdate.sh
}

View file

@ -99,7 +99,6 @@ on() {
while ! printf %s "$(mmcli -L)" 2> /dev/null | grep -qoE 'Modem\/([0-9]+)'; do
TRIES=$((TRIES+1))
if [ "$TRIES" -eq 10 ]; then
printf "failed\n" > "$MODEMSTATEFILE"
notify-send --urgency=critical "We failed to start the modem monitor. We may need hard reboot."
fi
sleep 5
@ -128,4 +127,5 @@ case "$1" in
off) off;;
esac
sleep 1
sxmo_statusbarupdate.sh