fix: cap batt percentage at 100

resolves #141
This commit is contained in:
Jan De Dobbeleer 2020-11-11 13:33:26 +01:00 committed by Jan De Dobbeleer
parent 284f2cbccf
commit b0c7e66ae1

View file

@ -2,6 +2,7 @@ package main
import ( import (
"fmt" "fmt"
"math"
"github.com/distatus/battery" "github.com/distatus/battery"
) )
@ -42,6 +43,7 @@ func (b *batt) enabled() bool {
return true return true
} }
batteryPercentage := bt.Current / bt.Full * 100 batteryPercentage := bt.Current / bt.Full * 100
batteryPercentage = math.Min(100, batteryPercentage)
percentageText := fmt.Sprintf("%.0f", batteryPercentage) percentageText := fmt.Sprintf("%.0f", batteryPercentage)
var icon string var icon string
var colorPorperty Property var colorPorperty Property