PowerAdapter (Linux): checks if the device is present

This commit is contained in:
李通洲
2026-04-10 08:48:55 +08:00
parent b3603391eb
commit 4dc5033c80
2 changed files with 12 additions and 5 deletions
+1 -1
View File
@@ -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;
}
}
@@ -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';