~mil/sxmo-devel

sxmo-utils: Change statusbar to print to variable first. v1 REJECTED

Peter John Hartman: 1
 Change statusbar to print to variable first.

 1 files changed, 49 insertions(+), 49 deletions(-)
#635605 .build.yml success
I tried this. It doesnt solve the volume mute icon issue and it should
not fix the sway status bar crash.

I dont experienced the wi-fi icon you mentionned so I cant tell :S

I'll still add the stderr redirection.
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~mil/sxmo-devel/patches/26847/mbox | git am -3
Learn more about email & git

[PATCH sxmo-utils] Change statusbar to print to variable first. Export this patch

In dwm (and sway) I'd sometimes see doubling of, e.g., the Wi-Fi icon or 
things out of order in my status bar.  Gathering the printf to a 
variable first should fix that.

It also *might* fix the [error reading from status command] bug that 
happens in sway.

I also pipe audiocurrentdevice.sh stderr to dev/null to fix 
https://todo.sr.ht/~mil/sxmo-tickets/425


---
 configs/default_hooks/statusbar | 98 ++++++++++++++++-----------------
 1 file changed, 49 insertions(+), 49 deletions(-)

diff --git a/configs/default_hooks/statusbar b/configs/default_hooks/statusbar
index b39d5d8..134745c 100644
--- a/configs/default_hooks/statusbar
+++ b/configs/default_hooks/statusbar
@@ -5,7 +5,7 @@
. "$(which sxmo_common.sh)"

MMCLI="$(mmcli -m any -J)"

SOUT=
# In-call.. show length of call
if pgrep sxmo_modemcall.sh > /dev/null; then
	NOWS="$(date +"%s")"
@@ -15,76 +15,76 @@ if pgrep sxmo_modemcall.sh > /dev/null; then
		cut -f1
	)")"
	CALLSECONDS="$(printf "%s - %s" "$NOWS" "$CALLSTARTS" | bc)"
	printf "%ss " "$CALLSECONDS"
	SOUT="$(printf "%s%ss " "$SOUT" "$CALLSECONDS")"
fi

MODEMSTATUS=""
if [ -z "$MMCLI" ]; then
	printf ""
	SOUT="$(printf "%s" "$SOUT")"
else
	MODEMSTATUS="$(printf %s "$MMCLI" | jq -r .modem.generic.state)"
	case "$MODEMSTATUS" in
		locked)
			printf ""
			SOUT="$(printf "%s" "$SOUT")"
			;;
		registered|connected)
			MODEMSIGNAL="$(printf %s "$MMCLI" | jq -r '.modem.generic."signal-quality".value')"
			if [ "$MODEMSIGNAL" -lt 20 ]; then
				printf ""
				SOUT="$(printf "%s" "$SOUT")"
			elif [ "$MODEMSIGNAL" -lt 40 ]; then
				printf ""
				SOUT="$(printf "%s" "$SOUT")"
			elif [ "$MODEMSIGNAL" -lt 60 ]; then
				printf ""
				SOUT="$(printf "%s" "$SOUT")"
			elif [ "$MODEMSIGNAL" -lt 80 ]; then
				printf ""
				SOUT="$(printf "%s" "$SOUT")"
			else
				printf ""
				SOUT="$(printf "%s" "$SOUT")"
			fi
			;;
		disconnected)
			printf "ﲁ"
			SOUT="$(printf "%sﲁ" "$SOUT")"
			;;
	esac
fi

if [ "$MODEMSTATUS" = "connected" ]; then
	printf " "
	SOUT="$(printf "%s " "$SOUT")"
	USEDTECHS="$(printf %s "$MMCLI" | jq -r '.modem.generic."access-technologies"[]')"
	case "$USEDTECHS" in
		*5gnr*)
			printf 5g # no icon yet
			SOUT="$(printf "%s5g" "$SOUT")" # no icon yet
			;;
		*lte*)
			printf ﰒ
			SOUT="$(printf "%sﰒ" "$SOUT")"
			;;
		*umts*|*hsdpa*|*hsupa*|*hspa*|*1xrtt*|*evdo0*|*evdoa*|*evdob*)
			printf ﰑ
			SOUT="$(printf "%sﰑ" "$SOUT")"
			;;
		*edge*)
			printf E
			SOUT="$(printf "%sE" "$SOUT")"
			;;
		*pots*|*gsm*|*gprs*)
			printf ﰐ
			SOUT="$(printf "%sﰐ" "$SOUT")"
			;;
	esac
fi

if pgrep -f sxmo_modemmonitor.sh > /dev/null; then
	printf " "
	SOUT="$(printf "%s " "$SOUT")"
fi

WLANSTATE="$(tr -d "\n" < /sys/class/net/wlan0/operstate)"
if [ "$WLANSTATE" = "up" ]; then
	printf " "
	SOUT="$(printf "%s " "$SOUT")"
fi

# symbol if wireguard/vpn is connected
VPNDEVICE="$(nmcli con show | grep vpn | awk '{ print $4 }')"
WGDEVICE="$(nmcli con show | grep wireguard | awk '{ print $4 }')"
if [ -n "$VPNDEVICE" ] && [ "$VPNDEVICE" != "--" ]; then
	printf " "
	SOUT="$(printf "%s " "$SOUT")"
elif [ -n "$WGDEVICE" ] && [ "$WGDEVICE" != "--" ]; then
	printf " "
	SOUT="$(printf "%s " "$SOUT")"
fi

# Find battery and get percentage + status
@@ -95,60 +95,60 @@ for power_supply in /sys/class/power_supply/*; do
	fi
done

printf " "
SOUT="$(printf "%s " "$SOUT")"
if [ "$BATSTATUS" = "C" ]; then
	if [ "$PCT" -lt 20 ]; then
		printf ""
		SOUT="$(printf "%s" "$SOUT")"
	elif [ "$PCT" -lt 30 ]; then
		printf ""
		SOUT="$(printf "%s" "$SOUT")"
	elif [ "$PCT" -lt 40 ]; then
		printf ""
		SOUT="$(printf "%s" "$SOUT")"
	elif [ "$PCT" -lt 60 ]; then
		printf ""
		SOUT="$(printf "%s" "$SOUT")"
	elif [ "$PCT" -lt 80 ]; then
		printf ""
		SOUT="$(printf "%s" "$SOUT")"
	elif [ "$PCT" -lt 90 ]; then
		printf ""
		SOUT="$(printf "%s" "$SOUT")"
	else
		printf ""
		SOUT="$(printf "%s" "$SOUT")"
	fi
else
	if [ "$PCT" -lt 10 ]; then
		printf ""
		SOUT="$(printf "%s" "$SOUT")"
	elif [ "$PCT" -lt 20 ]; then
		printf ""
		SOUT="$(printf "%s" "$SOUT")"
	elif [ "$PCT" -lt 30 ]; then
		printf ""
		SOUT="$(printf "%s" "$SOUT")"
	elif [ "$PCT" -lt 40 ]; then
		printf ""
		SOUT="$(printf "%s" "$SOUT")"
	elif [ "$PCT" -lt 50 ]; then
		printf ""
		SOUT="$(printf "%s" "$SOUT")"
	elif [ "$PCT" -lt 60 ]; then
		printf ""
		SOUT="$(printf "%s" "$SOUT")"
	elif [ "$PCT" -lt 70 ]; then
		printf ""
		SOUT="$(printf "%s" "$SOUT")"
	elif [ "$PCT" -lt 80 ]; then
		printf ""
		SOUT="$(printf "%s" "$SOUT")"
	elif [ "$PCT" -lt 90 ]; then
		printf ""
		SOUT="$(printf "%s" "$SOUT")"
	else
		printf ""
		SOUT="$(printf "%s" "$SOUT")"
	fi
fi

[ -z "$SXMO_BAR_HIDE_BAT_PER" ] && printf " %s%%" "$PCT"
[ -z "$SXMO_BAR_HIDE_BAT_PER" ] && SOUT="$(printf "%s %s%%" "$SOUT" "$PCT")"

printf " "
SOUT="$(printf "%s " "$SOUT")"

# Volume
AUDIODEV="$(sxmo_audiocurrentdevice.sh)"
AUDIODEV="$(sxmo_audiocurrentdevice.sh 2>/dev/null)"
AUDIOSYMBOL="$(printf %s "$AUDIODEV" | cut -c1)"
if [ "$AUDIOSYMBOL" = "L" ] || [ "$AUDIOSYMBOL" = "N" ] || [ "$AUDIOSYMBOL" = "M" ]; then
	printf "" #pipewire or speakers or none, use no special symbol
	SOUT="$(printf "%s" "$SOUT")" #pipewire or speakers or none, use no special symbol
elif [ "$AUDIOSYMBOL" = "H" ]; then
	printf " "
	SOUT="$(printf "%s " "$SOUT")"
elif [ "$AUDIOSYMBOL" = "E" ]; then
	printf " " #earpiece
	SOUT="$(printf "%s " "$SOUT")" #earpiece
fi
VOL=0
[ "$AUDIODEV" = "None" ] || VOL="$(
@@ -160,15 +160,15 @@ VOL=0
)"
if [ "$AUDIODEV" != "None" ]; then
	if [ "$VOL" -gt 66 ]; then
		printf ""
		SOUT="$(printf "%s" "$SOUT")"
	elif [ "$VOL" -gt 33 ]; then
		printf ""
		SOUT="$(printf "%s" "$SOUT")"
	elif [ "$VOL" -gt 0 ]; then
		printf ""
		SOUT="$(printf "%s" "$SOUT")"
	elif [ "$VOL" -eq 0 ]; then
		printf "ﱝ"
		SOUT="$(printf "%sﱝ" "$SOUT")"
	fi
fi

printf " %s\0" "$(date +%R)"
printf "%s %s\0" "$SOUT" "$(date +%R)"

-- 
2.34.0
sxmo-utils/patches/.build.yml: SUCCESS in 21s

[Change statusbar to print to variable first.][0] from [Peter John Hartman][1]

[0]: https://lists.sr.ht/~mil/sxmo-devel/patches/26847
[1]: mailto:peterjohnhartman@gmail.com

✓ #635605 SUCCESS sxmo-utils/patches/.build.yml https://builds.sr.ht/~mil/job/635605