mirror of
https://github.com/henrygd/beszel.git
synced 2025-12-16 18:26:16 +01:00
fix battery nil pointer error #1353
This commit is contained in:
@@ -10,8 +10,10 @@ import (
|
||||
"github.com/distatus/battery"
|
||||
)
|
||||
|
||||
var systemHasBattery = false
|
||||
var haveCheckedBattery = false
|
||||
var (
|
||||
systemHasBattery = false
|
||||
haveCheckedBattery = false
|
||||
)
|
||||
|
||||
// HasReadableBattery checks if the system has a battery and returns true if it does.
|
||||
func HasReadableBattery() bool {
|
||||
@@ -21,7 +23,7 @@ func HasReadableBattery() bool {
|
||||
haveCheckedBattery = true
|
||||
batteries, err := battery.GetAll()
|
||||
for _, bat := range batteries {
|
||||
if bat.Full > 0 {
|
||||
if bat != nil && (bat.Full > 0 || bat.Design > 0) {
|
||||
systemHasBattery = true
|
||||
break
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user