freebsd: fix battery-related bug (#1081)

This commit is contained in:
henrygd
2025-08-26 18:39:42 -04:00
parent e2a57dc43b
commit b13915b76f
5 changed files with 69 additions and 34 deletions

View File

@@ -2,6 +2,7 @@ package agent
import (
"beszel"
"beszel/internal/agent/battery"
"beszel/internal/entities/system"
"bufio"
"fmt"
@@ -64,13 +65,6 @@ func (a *Agent) initializeSystemInfo() {
} else {
a.zfs = true
}
// battery
if _, _, err := getBatteryStats(); err != nil {
slog.Debug("No battery detected", "err", err)
} else {
a.hasBattery = true
}
}
// Returns current info, stats about the host system
@@ -78,8 +72,8 @@ func (a *Agent) getSystemStats() system.Stats {
systemStats := system.Stats{}
// battery
if a.hasBattery {
systemStats.Battery[0], systemStats.Battery[1], _ = getBatteryStats()
if battery.HasReadableBattery() {
systemStats.Battery[0], systemStats.Battery[1], _ = battery.GetBatteryStats()
}
// cpu percent