Add Dual-SIM Dual Standby (DSDS), outgoing SIM selection, and instant charging icon update
This commit is contained in:
1 parent
5132deb4d8
commit
46f1255905
28 files changed
+2560
-280
No files matched your search
@@ -1,76 +1,119 @@
|
||||
#!/bin/sh
|
||||
# configversion: d031535bc22ba19d69704317b8d50560
|
||||
|
||||
export XDG_RUNTIME_DIR="${XDG_RUNTIME_DIR:-/run/user/10000}"
|
||||
export DISPLAY="${DISPLAY:-:0}"
|
||||
export PATH="/usr/share/sxmo/default_hooks:/usr/bin:/bin:/usr/sbin:/sbin:$PATH"
|
||||
|
||||
SET_LED_PATH="$XDG_RUNTIME_DIR/sxmo_hook_battery_set_led"
|
||||
|
||||
object="${1:-/org/freedesktop/UPower/devices/battery_default}"
|
||||
event="${2:-device changed}"
|
||||
if [ "${1:-}" = "udev" ]; then
|
||||
object="/org/freedesktop/UPower/devices/battery_default"
|
||||
event="device changed"
|
||||
if [ "${2:-}" != "recheck" ]; then
|
||||
(sleep 2; "$0" udev recheck >/dev/null 2>&1) &
|
||||
fi
|
||||
else
|
||||
object="${1:-/org/freedesktop/UPower/devices/battery_default}"
|
||||
event="${2:-device changed}"
|
||||
fi
|
||||
|
||||
case "$event" in
|
||||
"device changed") ;;
|
||||
*) exit 0 ;;
|
||||
"device changed") ;;
|
||||
*) exit 0 ;;
|
||||
esac
|
||||
|
||||
case "$object" in
|
||||
*/battery_*)
|
||||
raw_name="${object##*/battery_}"
|
||||
;;
|
||||
*)
|
||||
exit 0
|
||||
;;
|
||||
*/battery_*)
|
||||
raw_name="${object##*/battery_}"
|
||||
;;
|
||||
*)
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
|
||||
sysfs_dir=""
|
||||
if [ -d "/sys/class/power_supply/$raw_name" ]; then
|
||||
sysfs_dir="/sys/class/power_supply/$raw_name"
|
||||
name="$raw_name"
|
||||
sysfs_dir="/sys/class/power_supply/$raw_name"
|
||||
name="$raw_name"
|
||||
else
|
||||
for d in /sys/class/power_supply/*; do
|
||||
[ -r "$d/type" ] || continue
|
||||
read -r pstype < "$d/type" 2>/dev/null || continue
|
||||
if [ "$pstype" = "Battery" ]; then
|
||||
sysfs_dir="$d"
|
||||
name="${d##*/}"
|
||||
break
|
||||
fi
|
||||
done
|
||||
for d in /sys/class/power_supply/*; do
|
||||
[ -r "$d/type" ] || continue
|
||||
read -r pstype < "$d/type" 2>/dev/null || continue
|
||||
if [ "$pstype" = "Battery" ]; then
|
||||
sysfs_dir="$d"
|
||||
name="${d##*/}"
|
||||
break
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
if [ -n "$sysfs_dir" ] && [ -r "$sysfs_dir/capacity" ] && [ -r "$sysfs_dir/status" ]; then
|
||||
read -r percentage < "$sysfs_dir/capacity" 2>/dev/null || percentage=""
|
||||
read -r raw_status < "$sysfs_dir/status" 2>/dev/null || raw_status=""
|
||||
case "$raw_status" in
|
||||
"Full"|"full") state="fully-charged" ;;
|
||||
"Charging"|"charging") state="charging" ;;
|
||||
"Discharging"|"discharging"|"Not charging"|"not charging") state="discharging" ;;
|
||||
*) state="unknown" ;;
|
||||
esac
|
||||
read -r percentage < "$sysfs_dir/capacity" 2>/dev/null || percentage=""
|
||||
read -r raw_status < "$sysfs_dir/status" 2>/dev/null || raw_status=""
|
||||
case "$raw_status" in
|
||||
"Full"|"full") state="fully-charged" ;;
|
||||
"Charging"|"charging") state="charging" ;;
|
||||
"Discharging"|"discharging"|"Not charging"|"not charging") state="discharging" ;;
|
||||
*) state="unknown" ;;
|
||||
esac
|
||||
else
|
||||
exit 0
|
||||
exit 0
|
||||
fi
|
||||
|
||||
chgr_online=""
|
||||
if [ -r "/sys/class/power_supply/pm8916-lbc-chgr/online" ]; then
|
||||
read -r chgr_online < "/sys/class/power_supply/pm8916-lbc-chgr/online" 2>/dev/null || chgr_online=""
|
||||
else
|
||||
for d in /sys/class/power_supply/*; do
|
||||
[ -r "$d/type" ] && [ -r "$d/online" ] || continue
|
||||
read -r pstype < "$d/type" 2>/dev/null || continue
|
||||
case "$pstype" in
|
||||
USB*|Mains)
|
||||
read -r chgr_online < "$d/online" 2>/dev/null || chgr_online=""
|
||||
[ -n "$chgr_online" ] && break
|
||||
;;
|
||||
esac
|
||||
done
|
||||
fi
|
||||
|
||||
if [ "$chgr_online" = "1" ] && [ "$state" = "discharging" ]; then
|
||||
case "$percentage" in
|
||||
''|*[!0-9]*) state="charging" ;;
|
||||
*)
|
||||
if [ "$percentage" -ge 99 ]; then
|
||||
state="fully-charged"
|
||||
else
|
||||
state="charging"
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
elif [ "$chgr_online" = "0" ] && { [ "$state" = "charging" ] || [ "$state" = "fully-charged" ]; }; then
|
||||
state="discharging"
|
||||
fi
|
||||
|
||||
if [ -z "$name" ] || [ -z "$state" ] || [ -z "$percentage" ] || [ "$state" = "unknown" ]; then
|
||||
exit 0
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ -z "$SXMO_DISABLE_LEDS" ]; then
|
||||
if [ "$percentage" -lt 25 ] && [ ! -f "$SET_LED_PATH" ]; then
|
||||
touch "$SET_LED_PATH"
|
||||
sxmo_led.sh set red 100
|
||||
elif [ -f "$SET_LED_PATH" ]; then
|
||||
rm "$SET_LED_PATH"
|
||||
sxmo_led.sh set red 0
|
||||
fi
|
||||
if [ "$percentage" -lt 25 ] && [ ! -f "$SET_LED_PATH" ]; then
|
||||
touch "$SET_LED_PATH"
|
||||
sxmo_led.sh set red 100
|
||||
elif [ -f "$SET_LED_PATH" ]; then
|
||||
rm "$SET_LED_PATH"
|
||||
sxmo_led.sh set red 0
|
||||
fi
|
||||
fi
|
||||
|
||||
CACHE_FILE="${XDG_RUNTIME_DIR:-/tmp}/sxmo_bat_state_${name}"
|
||||
ICON_FILE="${XDG_RUNTIME_DIR:-/run/user/10000}/sxmo_status/${SXMO_STATUS_NAME:-default}/040-battery-icon-${name}"
|
||||
NEW_VAL="${state}:${percentage}"
|
||||
if [ -r "$CACHE_FILE" ] && [ -f "$ICON_FILE" ]; then
|
||||
read -r OLD_VAL < "$CACHE_FILE" 2>/dev/null || OLD_VAL=""
|
||||
if [ "$OLD_VAL" = "$NEW_VAL" ]; then
|
||||
exit 0
|
||||
fi
|
||||
read -r OLD_VAL < "$CACHE_FILE" 2>/dev/null || OLD_VAL=""
|
||||
if [ "$OLD_VAL" = "$NEW_VAL" ]; then
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
printf '%s\n' "$NEW_VAL" > "$CACHE_FILE"
|
||||
|
||||
|
||||
Reference in new issue
Block a user