From 0e1b7599afdc74dc95ccdc1d61cdccebca56824b Mon Sep 17 00:00:00 2001 From: aonemd Date: Fri, 2 Feb 2018 23:32:28 +0200 Subject: [PATCH] Fix displaying 100% battery level --- components/battery_level.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/components/battery_level.go b/components/battery_level.go index fdf1e4f..79b5d47 100644 --- a/components/battery_level.go +++ b/components/battery_level.go @@ -29,7 +29,11 @@ func main() { remainingTimePattern, _ := regexp.Compile("[01][0-9]:[0-9][0-9]") icon := iconPattern.FindString(string(response)) - power, _ := strconv.Atoi(powerPattern.FindString(string(response))[:2]) + powerString := powerPattern.FindString(string(response)) + if last := len(powerString) - 1; last >= 0 && powerString[last] == '%' { + powerString = powerString[:last] + } + power, _ := strconv.Atoi(powerString) remainingTime := remainingTimePattern.FindString(string(response)) switch icon {