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