mirror of
https://github.com/henrygd/beszel.git
synced 2025-10-30 10:07:02 +00:00
update HasReadableBattery to check all batteries
This commit is contained in:
@@ -5,8 +5,6 @@ package battery
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"log/slog"
|
||||
|
||||
"github.com/distatus/battery"
|
||||
@@ -21,15 +19,13 @@ func HasReadableBattery() bool {
|
||||
return systemHasBattery
|
||||
}
|
||||
haveCheckedBattery = true
|
||||
batteries,err := battery.GetAll()
|
||||
if err != nil {
|
||||
// even if there's errors getting some batteries, the system
|
||||
// definitely has a battery if the list is not empty.
|
||||
// This list will include everything `battery` can find,
|
||||
// including things like bluetooth devices.
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
batteries, err := battery.GetAll()
|
||||
for _, bat := range batteries {
|
||||
if bat.Full > 0 {
|
||||
systemHasBattery = true
|
||||
break
|
||||
}
|
||||
}
|
||||
systemHasBattery = len(batteries) > 0
|
||||
if !systemHasBattery {
|
||||
slog.Debug("No battery found", "err", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user