diff --git a/segment_battery.go b/segment_battery.go index d77c708c..8c588128 100644 --- a/segment_battery.go +++ b/segment_battery.go @@ -43,13 +43,20 @@ func (b *batt) enabled() bool { } displayError := b.props.getBool(DisplayError, false) - if err != nil && !displayError { - b.percentageText = "100%" + if err != nil && displayError { + b.percentageText = "BATT ERR" return true } if err != nil { - b.percentageText = "BATT ERR" - return true + // On Windows, it sometimes errors when the battery is full. + // This hack ensures we display a fully charged battery, even if + // that state can be incorrect. It's better to "ignore" the error + // than to not display the segment at all as that will confuse users. + bt = &battery.Battery{ + Current: 100, + Full: 100, + State: battery.Full, + } } batteryPercentage := bt.Current / bt.Full * 100 batteryPercentage = math.Min(100, batteryPercentage) diff --git a/segment_battery_test.go b/segment_battery_test.go index 839a3358..4f098ae4 100644 --- a/segment_battery_test.go +++ b/segment_battery_test.go @@ -147,7 +147,7 @@ func TestBatteryErrorHidden(t *testing.T) { env: env, } assert.True(t, b.enabled()) - assert.Equal(t, "100%", b.string()) + assert.Equal(t, "100", b.string()) } func TestBatteryDischargingAndDisplayChargingDisabled(t *testing.T) {