Skip to content

Commit 92259ca

Browse files
Merge pull request #154 from ruiiiijiiiiang/fix/skip-unused-battery
fixed issue with unused battery
2 parents 2623f97 + 3ce1c8c commit 92259ca

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/catnaplib/platform/probe.nim

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,10 @@ proc getBattery*(): string =
204204
# Collect all batterys
205205
for dir in os.walk_dir(powerPath):
206206
if re.match(os.last_path_part(dir.path), BATTERY_REGEX):
207-
batterys.add((parseInt($dir.path[^1]), dir.path & "/"))
207+
let batteryPath = dir.path & "/"
208+
# Only check if battery has capacity and status
209+
if fileExists(batteryPath & "capacity") and fileExists(batteryPath & "status"):
210+
batterys.add((parseInt($dir.path[^1]), batteryPath))
208211

209212
if batterys.len < 1:
210213
logError("No battery detected!")

0 commit comments

Comments
 (0)