update HasReadableBattery to check all batteries

This commit is contained in:
henrygd
2025-10-25 14:06:25 -04:00
parent d608cf0955
commit 1dee63a0eb

View File

@@ -5,8 +5,6 @@ package battery
import ( import (
"errors" "errors"
"fmt"
"os"
"log/slog" "log/slog"
"github.com/distatus/battery" "github.com/distatus/battery"
@@ -21,15 +19,13 @@ func HasReadableBattery() bool {
return systemHasBattery return systemHasBattery
} }
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)
} }