@ -4,54 +4,92 @@
# shellcheck source=scripts/core/sxmo_common.sh
# shellcheck source=scripts/core/sxmo_common.sh
. " $( dirname " $0 " ) /sxmo_common.sh "
. " $( dirname " $0 " ) /sxmo_common.sh "
trap "update" USR1
percenticon( ) {
if [ " $1 " -lt 20 ] ; then
printf " "
elif [ " $1 " -lt 40 ] ; then
printf " "
elif [ " $1 " -lt 60 ] ; then
printf " "
elif [ " $1 " -lt 80 ] ; then
printf " "
else
printf " "
fi
}
bar( ) {
MMCLI = " $( mmcli -m any -J) "
update( ) {
# In-call.. show length of call
# In-call.. show length of call
CALLINFO = " "
if pgrep sxmo_modemcall.sh > /dev/null; then
if pgrep -f sxmo_modemcall.sh; then
NOWS = " $( date +"%s" ) "
NOWS = " $( date +"%s" ) "
CALLSTARTS = " $( date +"%s" -d " $(
CALLSTARTS = " $( date +"%s" -d " $(
grep -aE 'call_start|call_pickup' " $XDG_DATA_HOME " /sxmo/modem/modemlog.tsv |
grep -aE 'call_start|call_pickup' " $XDG_DATA_HOME " /sxmo/modem/modemlog.tsv |
tail -n1 |
tail -n1 |
cut -f1
cut -f1
) ")"
) ")"
CALLSECONDS = " $( echo " $NOWS " - " $CALLSTARTS " | bc) "
CALLSECONDS = " $( printf "%s - %s" " $NOWS " " $CALLSTARTS " | bc) "
CALLINFO = " ${ CALLSECONDS } s "
printf "%ss " " $CALLSECONDS "
fi
fi
# symbol if wireguard/vpn is connected
MODEMSTATUS = ""
VPN = ""
if [ -z " $MMCLI " ] ; then
VPNDEVICE = " $( nmcli con show | grep vpn | awk '{ print $4 }' ) "
printf " "
WGDEVICE = " $( nmcli con show | grep wireguard | awk '{ print $4 }' ) "
else
if [ -n " $VPNDEVICE " ] && [ " $VPNDEVICE " != "--" ] ; then
MODEMSTATUS = " $( printf %s " $MMCLI " | jq -r .modem.generic.state) "
VPN = " "
case " $MODEMSTATUS " in
elif [ -n " $WGDEVICE " ] && [ " $WGDEVICE " != "--" ] ; then
locked)
VPN = " "
printf " "
; ;
registered| connected)
MODEMSIGNAL = " $( printf %s " $MMCLI " | jq -r '.modem.generic."signal-quality".value' ) "
percenticon " $MODEMSIGNAL "
; ;
disconnected)
printf "ﲁ"
; ;
esac
fi
if [ " $MODEMSTATUS " = "connected" ] ; then
printf " "
USEDTECHS = " $( printf %s " $MMCLI " | jq -r '.modem.generic."access-technologies"[]' ) "
case " $USEDTECHS " in
*5gnr*)
printf 5g # no icon yet
; ;
*lte*)
printf ﰒ
; ;
*umts*| *hsdpa*| *hsupa*| *hspa*| *1xrtt*| *evdo0*| *evdoa*| *evdob*)
printf ﰑ
; ;
*edge*)
printf E
; ;
*pots*| *gsm*| *gprs*)
printf ﰐ
; ;
esac
fi
if pgrep -f sxmo_modemmonitor.sh > /dev/null; then
printf " "
fi
fi
# W symbol if wireless is connect
WIRELESS = ""
WLANSTATE = " $( tr -d "\n" < /sys/class/net/wlan0/operstate) "
WLANSTATE = " $( tr -d "\n" < /sys/class/net/wlan0/operstate) "
if [ " $WLANSTATE " = "up" ] ; then
if [ " $WLANSTATE " = "up" ] ; then
WIRELESS = " "
printf " "
fi
fi
# M symbol if modem monitoring is on & modem present
# symbol if wireguard/vpn is connected
MODEMMON = ""
VPNDEVICE = " $( nmcli con show | grep vpn | awk '{ print $4 }' ) "
if [ -f " $MODEMSTATEFILE " ] ; then
WGDEVICE = " $( nmcli con show | grep wireguard | awk '{ print $4 }' ) "
MODEMSTATE = " $( cat " $MODEMSTATEFILE " ) "
if [ -n " $VPNDEVICE " ] && [ " $VPNDEVICE " != "--" ] ; then
if [ locked = " $MODEMSTATE " ] ; then
printf " "
MODEMMON = " "
elif [ -n " $WGDEVICE " ] && [ " $WGDEVICE " != "--" ] ; then
elif [ registered = " $MODEMSTATE " ] ; then
printf " "
MODEMMON = " "
elif [ connected = " $MODEMSTATE " ] ; then
MODEMMON = " "
elif [ failed = " $MODEMSTATE " ] || [ disconnected = " $MODEMSTATE " ] ; then
MODEMMON = " "
else
MODEMMON = " "
fi
fi
fi
# Find battery and get percentage + status
# Find battery and get percentage + status
@ -62,55 +100,60 @@ update() {
fi
fi
done
done
printf " "
if [ " $BATSTATUS " = "C" ] ; then
if [ " $BATSTATUS " = "C" ] ; then
if [ " $PCT " -lt 20 ] ; then
if [ " $PCT " -lt 20 ] ; then
BATSTATUS = " $PCT % "
printf " "
elif [ " $PCT " -lt 30 ] ; then
elif [ " $PCT " -lt 30 ] ; then
BATSTATUS = " $PCT % "
printf " "
elif [ " $PCT " -lt 40 ] ; then
elif [ " $PCT " -lt 40 ] ; then
BATSTATUS = " $PCT % "
printf " "
elif [ " $PCT " -lt 60 ] ; then
elif [ " $PCT " -lt 60 ] ; then
BATSTATUS = " $PCT % "
printf " "
elif [ " $PCT " -lt 80 ] ; then
elif [ " $PCT " -lt 80 ] ; then
BATSTATUS = " $PCT % "
printf " "
elif [ " $PCT " -lt 90 ] ; then
elif [ " $PCT " -lt 90 ] ; then
BATSTATUS = " $PCT % "
printf " "
else
else
BATSTATUS = " $PCT % "
printf " "
fi
fi
else
else
if [ " $PCT " -lt 10 ] ; then
if [ " $PCT " -lt 10 ] ; then
BATSTATUS = " $PCT % "
printf " "
elif [ " $PCT " -lt 20 ] ; then
elif [ " $PCT " -lt 20 ] ; then
BATSTATUS = " $PCT % "
printf " "
elif [ " $PCT " -lt 30 ] ; then
elif [ " $PCT " -lt 30 ] ; then
BATSTATUS = " $PCT % "
printf " "
elif [ " $PCT " -lt 40 ] ; then
elif [ " $PCT " -lt 40 ] ; then
BATSTATUS = " $PCT % "
printf " "
elif [ " $PCT " -lt 50 ] ; then
elif [ " $PCT " -lt 50 ] ; then
BATSTATUS = " $PCT % "
printf " "
elif [ " $PCT " -lt 60 ] ; then
elif [ " $PCT " -lt 60 ] ; then
BATSTATUS = " $PCT % "
printf " "
elif [ " $PCT " -lt 70 ] ; then
elif [ " $PCT " -lt 70 ] ; then
BATSTATUS = " $PCT % "
printf " "
elif [ " $PCT " -lt 80 ] ; then
elif [ " $PCT " -lt 80 ] ; then
BATSTATUS = " $PCT % "
printf " "
elif [ " $PCT " -lt 90 ] ; then
elif [ " $PCT " -lt 90 ] ; then
BATSTATUS = " $PCT % "
printf " "
else
else
BATSTATUS = " $PCT % "
printf " "
fi
fi
fi
fi
[ -z " $SXMO_BAR_HIDE_BAT_PER " ] && printf " %s%%" " $PCT "
printf " "
# Volume
# Volume
AUDIODEV = " $( sxmo_audiocurrentdevice.sh) "
AUDIODEV = " $( sxmo_audiocurrentdevice.sh) "
AUDIOSYMBOL = $( echo " $AUDIODEV " | cut -c1)
AUDIOSYMBOL = " $( printf %s " $AUDIODEV " | cut -c1) "
if [ " $AUDIOSYMBOL " = "L" ] || [ " $AUDIOSYMBOL " = "N" ] ; then
if [ " $AUDIOSYMBOL " = "L" ] || [ " $AUDIOSYMBOL " = "N" ] ; then
AUDIOSYMBOL = "" #speakers or none, use no special symbol
printf "" #speakers or none, use no special symbol
elif [ " $AUDIOSYMBOL " = "H" ] ; then
elif [ " $AUDIOSYMBOL " = "H" ] ; then
AUDIOSYMBOL = " "
printf " "
elif [ " $AUDIOSYMBOL " = "E" ] ; then
elif [ " $AUDIOSYMBOL " = "E" ] ; then
AUDIOSYMBOL = " " #earpiece
printf " " #earpiece
fi
fi
VOL = 0
VOL = 0
[ " $AUDIODEV " = "None" ] || VOL = " $(
[ " $AUDIODEV " = "None" ] || VOL = " $(
@ -121,32 +164,45 @@ update() {
xargs printf %.0f
xargs printf %.0f
) "
) "
if [ " $AUDIODEV " != "None" ] ; then
if [ " $AUDIODEV " != "None" ] ; then
if [ " $VOL " -eq 0 ] ; then
if [ " $VOL " -gt 66 ] ; then
VOLUMESYMBOL = "ﱝ "
printf " "
elif [ " $VOL " -lt 25 ] ; then
elif [ " $VOL " -gt 33 ] ; then
VOLUMESYMBOL = "奄 "
printf " "
elif [ " $VOL " -gt 75 ] ; then
elif [ " $VOL " -gt 0 ] ; then
VOLUMESYMBOL = "墳 "
printf " "
els e
elif [ " $VOL " - eq 0 ] ; then
VOLUMESYMBOL = "奔 "
printf "ﱝ "
fi
fi
fi
fi
# Time
TIME = " $( date +%R) "
BAR = " $( echo " ${ CALLINFO } ${ MODEMMON } ${ WIRELESS } ${ VPN } ${ AUDIOSYMBOL } ${ VOLUMESYMBOL } ${ BATSTATUS } ${ TIME } " | sed 's| \+| |g' ) "
printf " %s\0" " $( date +%R) "
}
case " $( sxmo_wm.sh) " in
WM = " $( sxmo_wm.sh) "
sway) printf "%s\n" " $BAR " ; ;
dwm) xsetroot -name " $BAR " ; ;
forceupdate( ) {
esac
kill " $SLEEPID "
}
}
trap "forceupdate" USR1
# E.g. on first boot justs to make sure the bar comes in quickly
update( ) {
update
BAR = " $( bar) "
[ -z " $SLEEPID " ] && return # to prevent mid rendering interuption
printf %s " $BAR " | case " $WM " in
sway| ssh) xargs -0 printf "%s\n" ; ;
dwm) xargs -0 xsetroot -name; ;
esac
}
while :
while :
do
do
sleep 30 & wait
sleep 10 &
update
SLEEPID = $!
update &
UPDATEID = $!
wait " $SLEEPID "
unset SLEEPID
wait " $UPDATEID "
done
done