Skip to content

Commit

Permalink
fix: avoid crash on system with no battey in battery segment
Browse files Browse the repository at this point in the history
  • Loading branch information
lnu authored and JanDeDobbeleer committed Jan 5, 2021
1 parent 86d2c3c commit c57368c
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/segment_battery.go
Expand Up @@ -37,11 +37,6 @@ const (
func (b *batt) enabled() bool {
bt, err := b.env.getBatteryInfo()

display := b.props.getBool(DisplayCharging, true)
if !display && (bt.State == battery.Charging || bt.State == battery.Full) {
return false
}

displayError := b.props.getBool(DisplayError, false)
if err != nil && displayError {
b.percentageText = "BATT ERR"
Expand All @@ -58,6 +53,12 @@ func (b *batt) enabled() bool {
State: battery.Full,
}
}

display := b.props.getBool(DisplayCharging, true)
if !display && (bt.State == battery.Charging || bt.State == battery.Full) {
return false
}

batteryPercentage := bt.Current / bt.Full * 100
batteryPercentage = math.Min(100, batteryPercentage)
percentageText := fmt.Sprintf("%.0f", batteryPercentage)
Expand Down

0 comments on commit c57368c

Please sign in to comment.