Fixes #15, crash when battery info includes devices
This commit is contained in:
parent
a2d04d316d
commit
cbad9c124e
|
@ -52,8 +52,25 @@ func (b *BatteryWidget) Scale(i int) {
|
||||||
func (self *BatteryWidget) update() {
|
func (self *BatteryWidget) update() {
|
||||||
batteries, err := battery.GetAll()
|
batteries, err := battery.GetAll()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("failed to get battery info: %v", err)
|
switch errt := err.(type) {
|
||||||
return
|
case battery.ErrFatal:
|
||||||
|
log.Printf("fatal error fetching battery info: %v", err)
|
||||||
|
return
|
||||||
|
case battery.Errors:
|
||||||
|
batts := make([]*battery.Battery, 0)
|
||||||
|
for i, e := range errt {
|
||||||
|
if e == nil {
|
||||||
|
batts = append(batts, batteries[i])
|
||||||
|
} else {
|
||||||
|
log.Printf("recoverable error fetching battery info; skipping battery: %v", e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(batts) < 1 {
|
||||||
|
log.Print("no usable batteries found")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
batteries = batts
|
||||||
|
}
|
||||||
}
|
}
|
||||||
for i, battery := range batteries {
|
for i, battery := range batteries {
|
||||||
id := makeId(i)
|
id := makeId(i)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user