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