From 4dc5033c80f49bc3024a97ac548256b4f3e74e09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Fri, 10 Apr 2026 08:48:55 +0800 Subject: [PATCH] PowerAdapter (Linux): checks if the device is present --- src/detection/battery/battery_linux.c | 2 +- src/detection/poweradapter/poweradapter_linux.c | 15 +++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/detection/battery/battery_linux.c b/src/detection/battery/battery_linux.c index 236d4d696..1434bb45e 100644 --- a/src/detection/battery/battery_linux.c +++ b/src/detection/battery/battery_linux.c @@ -48,7 +48,7 @@ static bool parseBattery(int dfd, const char* id, FFBatteryOptions* options, FFl ffStrbufTrimRightSpace(&tmpBuffer); FF_DEBUG("Battery \"%s\": Scope is \"%s\"", id, tmpBuffer.chars); - if (ffStrbufIgnCaseEqualS(&tmpBuffer, "Device")) { + if (ffStrbufEqualS(&tmpBuffer, "Device")) { return false; } } diff --git a/src/detection/poweradapter/poweradapter_linux.c b/src/detection/poweradapter/poweradapter_linux.c index cb7f7966e..f0423cc5e 100644 --- a/src/detection/poweradapter/poweradapter_linux.c +++ b/src/detection/poweradapter/poweradapter_linux.c @@ -9,22 +9,29 @@ static void parsePowerAdapter(int dfd, const char* id, FFlist* results) { FF_STRBUF_AUTO_DESTROY tmpBuffer = ffStrbufCreate(); + { + char present = '\0'; + if (ffReadFileDataRelative(dfd, "present", 1, &present) && present == '0') { + return; + } + } + // type must exist and be "Mains" if (ffReadFileBufferRelative(dfd, "type", &tmpBuffer)) { ffStrbufTrimRightSpace(&tmpBuffer); } - if (!ffStrbufIgnCaseEqualS(&tmpBuffer, "Mains")) { + if (!ffStrbufEqualS(&tmpBuffer, "Mains")) { return; } // scope may not exist or must not be "Device" (?) if (ffReadFileBufferRelative(dfd, "scope", &tmpBuffer)) { ffStrbufTrimRightSpace(&tmpBuffer); - } - if (ffStrbufIgnCaseEqualS(&tmpBuffer, "Device")) { - return; + if (ffStrbufEqualS(&tmpBuffer, "Device")) { + return; + } } char online = '\0';