Add error handling to battery.

This commit is contained in:
Ceda EI 2019-09-06 19:39:45 +05:30
parent ab5df51c2a
commit ffe7975dfa
1 changed files with 10 additions and 5 deletions

View File

@ -16,12 +16,17 @@ function wish_battery_set_colors() {
function wish_battery_main() { function wish_battery_main() {
local path=/sys/class/power_supply/$WISH_BATTERY_ID local path=/sys/class/power_supply/$WISH_BATTERY_ID
local battery=$(($(cat $path/charge_now) * 100 / $(cat $path/charge_full)))% local battery
if [[ -f $path/charge_now ]]; then
battery=$(($(cat $path/charge_now) * 100 / $(cat $path/charge_full)))%
if [[ $(cat $path/status) == "Charging" ]] || if [[ $(cat $path/status) == "Charging" ]] ||
[[ $(cat $path/status) == "Full" ]]; then [[ $(cat $path/status) == "Full" ]]; then
battery="$WISH_BATTERY_CHARGING $battery" battery="$WISH_BATTERY_CHARGING $battery"
else else
battery="$WISH_BATTERY_DISCHARGING $battery" battery="$WISH_BATTERY_DISCHARGING $battery"
fi fi
else
battery="$WISH_BATTERY_ID not found"
fi
wish_append $WISH_BATTERY_BG $WISH_BATTERY_FG " $battery " wish_append $WISH_BATTERY_BG $WISH_BATTERY_FG " $battery "
} }