diff --git a/scripts/core/sxmo_common.sh b/scripts/core/sxmo_common.sh index 60cee83..abe4f03 100644 --- a/scripts/core/sxmo_common.sh +++ b/scripts/core/sxmo_common.sh @@ -17,6 +17,8 @@ export CACHEDIR="$XDG_CACHE_HOME"/sxmo export LOGDIR="$XDG_DATA_HOME"/sxmo/modem # shellcheck disable=SC2034 export CONTACTFILE="$XDG_CONFIG_HOME/sxmo/contacts.tsv" +# shellcheck disable=SC2034 +export MODEMSTATEFILE="$XDG_RUNTIME_DIR/sxmo.modem.state" command -v "$KEYBOARD" > /dev/null || export KEYBOARD=svkbd-mobile-intl diff --git a/scripts/core/sxmo_statusbar.sh b/scripts/core/sxmo_statusbar.sh index aa6025e..bb97829 100755 --- a/scripts/core/sxmo_statusbar.sh +++ b/scripts/core/sxmo_statusbar.sh @@ -30,14 +30,16 @@ update() { # M symbol if modem monitoring is on & modem present MODEMMON="" - pgrep -f sxmo_modemmonitor.sh && MODEMMON="" - if [ -n "$MODEMMON" ]; then - if [ -f /tmp/modem.locked.state ]; then + if [ -f "$MODEMSTATEFILE" ]; then + MODEMSTATE="$(cat "$MODEMSTATEFILE")" + if [ locked = "$MODEMSTATE" ]; then MODEMMON="" - elif [ -f /tmp/modem.registered.state ]; then + elif [ registered = "$MODEMSTATE" ]; then MODEMMON="" - elif [ -f /tmp/modem.connected.state ]; then + elif [ connected = "$MODEMSTATE" ]; then MODEMMON="" + else + MODEMMON="" fi fi diff --git a/scripts/modem/sxmo_modemmonitor.sh b/scripts/modem/sxmo_modemmonitor.sh index bbc56f8..7fad094 100755 --- a/scripts/modem/sxmo_modemmonitor.sh +++ b/scripts/modem/sxmo_modemmonitor.sh @@ -12,6 +12,9 @@ err() { } gracefulexit() { + rm "$MODEMSTATEFILE" + sxmo_statusbarupdate.sh + sleep 1 echo "sxmo_modemmonitor: gracefully exiting (on signal or after error)">&2 kill -9 0 } @@ -183,15 +186,17 @@ checkfornewtexts() { } initialmodemstatus() { - rm /tmp/modem.*.state 2>/dev/null + touch "$MODEMSTATEFILE" state=$(mmcli -m "$(modem_n)") if echo "$state" | grep -q -E "^.*state:.*connected.*$"; then - touch /tmp/modem.connected.state + echo connected > "$MODEMSTATEFILE" elif echo "$state" | grep -q -E "^.*state:.*registered.*$"; then - touch /tmp/modem.registered.state + echo registered > "$MODEMSTATEFILE" elif echo "$state" | grep -q -E "^.*state:.*locked.*$"; then - touch /tmp/modem.locked.state + echo locked > "$MODEMSTATEFILE" pidof sxmo_unlocksim.sh || sxmo_unlocksim.sh & + else + echo unknown > "$MODEMSTATEFILE" fi } @@ -228,21 +233,22 @@ mainloop() { 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 - rm /tmp/modem.*.state 2>/dev/null # shellcheck disable=SC2034 read -r oldstate #unused but we need to read past it read -r newstate if echo "$newstate" | grep "int32 2"; then - touch /tmp/modem.locked.state + echo locked > "$MODEMSTATEFILE" pidof sxmo_unlocksim.sh || sxmo_unlocksim.sh & elif echo "$newstate" | grep "int32 8"; then - touch /tmp/modem.registered.state + echo registered > "$MODEMSTATEFILE" checkforfinishedcalls checkforincomingcalls checkfornewtexts elif echo "$newstate" | grep "int32 11"; then - touch /tmp/modem.connected.state + echo connected > "$MODEMSTATEFILE" #3G/2G/4G available + else + echo unknown > "$MODEMSTATEFILE" fi sxmo_statusbarupdate.sh fi @@ -253,7 +259,7 @@ mainloop() { wait wait - rm /tmp/modem.*.state 2>/dev/null + rm "$MODEMSTATEFILE" 2>/dev/null sxmo_statusbarupdate.sh }