fix: remove battery percentage on error

resolves #259
This commit is contained in:
Jan De Dobbeleer 2020-12-24 13:20:21 +01:00 committed by Jan De Dobbeleer
parent d62c3d6e37
commit 4641146b1e
2 changed files with 12 additions and 5 deletions

View file

@ -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)

View file

@ -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) {