From 886bde47d651aee37b47d53b8c74abf0ea51ab53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Thu, 9 Apr 2026 14:01:24 +0800 Subject: [PATCH] Battery (Linux): checks if battery's present before parsing --- src/detection/battery/battery_linux.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/detection/battery/battery_linux.c b/src/detection/battery/battery_linux.c index 5bf25f49f..29a259b6a 100644 --- a/src/detection/battery/battery_linux.c +++ b/src/detection/battery/battery_linux.c @@ -12,6 +12,14 @@ static bool parseBattery(int dfd, const char* id, FFBatteryOptions* options, FFlist* results, bool* acConnected) { FF_STRBUF_AUTO_DESTROY tmpBuffer = ffStrbufCreate(); + { + char present = '\0'; + if (ffReadFileDataRelative(dfd, "present", 1, &present) && present == '0') { + FF_DEBUG("Battery \"%s\": Not present", id); + return false; + } + } + // type must exist if (!ffReadFileBufferRelative(dfd, "type", &tmpBuffer)) { FF_DEBUG("Battery \"%s\": No type file", id);