Fix battery time showing hours instead of minutes (#5137)
When upower reported time in minutes, the value was incorrectly passed through the hours conversion path, displaying e.g. "25h" instead of "25m".
This commit is contained in:
@@ -7,19 +7,16 @@ battery_info=$(upower -i $(upower -e | grep BAT))
|
|||||||
echo "$battery_info" | awk '/time to (empty|full)/ {
|
echo "$battery_info" | awk '/time to (empty|full)/ {
|
||||||
value = $4
|
value = $4
|
||||||
unit = $5
|
unit = $5
|
||||||
if (unit == "minutes") {
|
if (unit ~ /^minute/) {
|
||||||
hours = int(value / 60)
|
printf "%dm", int(value)
|
||||||
minutes = int(value % 60)
|
|
||||||
} else {
|
} else {
|
||||||
hours = int(value)
|
hours = int(value)
|
||||||
minutes = int((value - hours) * 60)
|
minutes = int((value - hours) * 60)
|
||||||
}
|
if (minutes > 0) {
|
||||||
if (hours > 0 && minutes > 0) {
|
printf "%dh %dm", hours, minutes
|
||||||
printf "%dh %dm", hours, minutes
|
} else {
|
||||||
} else if (hours > 0) {
|
printf "%dh", hours
|
||||||
printf "%dh", hours
|
}
|
||||||
} else {
|
|
||||||
printf "%dm", minutes
|
|
||||||
}
|
}
|
||||||
exit
|
exit
|
||||||
}'
|
}'
|
||||||
|
|||||||
Reference in New Issue
Block a user