Skip to content

Commit bf1cd33

Browse files
committed
Battery (macOS): fix remaining time detection
1 parent a0ad38d commit bf1cd33

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

src/detection/battery/battery_apple.c

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,20 +57,24 @@ const char* ffDetectBattery(FFBatteryOptions* options, FFlist* results)
5757
ffCfDictGetInt(properties, CFSTR(kIOPMPSCycleCountKey), &cycleCount);
5858
battery->cycleCount = cycleCount < 0 ? 0 : (uint32_t) cycleCount;
5959

60-
if (!ffCfDictGetBool(properties, CFSTR(kIOPMPSExternalConnectedKey), &boolValue) && boolValue)
61-
ffStrbufAppendS(&battery->status, "AC connected, ");
62-
else
60+
battery->timeRemaining = -1;
61+
if (ffCfDictGetBool(properties, CFSTR(kIOPMPSExternalConnectedKey), &boolValue) == NULL)
6362
{
64-
ffStrbufAppendS(&battery->status, "Discharging, ");
65-
ffCfDictGetInt(properties, CFSTR(kIOPMPSTimeRemainingKey), &battery->timeRemaining); // in minutes
66-
if (battery->timeRemaining == 0xFFFF)
67-
battery->timeRemaining = -1;
63+
if (boolValue)
64+
ffStrbufAppendS(&battery->status, "AC connected, ");
6865
else
69-
battery->timeRemaining *= 60;
66+
{
67+
ffStrbufAppendS(&battery->status, "Discharging, ");
68+
ffCfDictGetInt(properties, CFSTR("AvgTimeToEmpty"), &battery->timeRemaining); // in minutes
69+
if (battery->timeRemaining < 0 || battery->timeRemaining >= 0xFFFF)
70+
battery->timeRemaining = -1;
71+
else
72+
battery->timeRemaining *= 60;
73+
}
7074
}
71-
if (!ffCfDictGetBool(properties, CFSTR(kIOPMPSIsChargingKey), &boolValue) && boolValue)
75+
if (ffCfDictGetBool(properties, CFSTR(kIOPMPSIsChargingKey), &boolValue) == NULL && boolValue)
7276
ffStrbufAppendS(&battery->status, "Charging, ");
73-
if (!ffCfDictGetBool(properties, CFSTR(kIOPMPSAtCriticalLevelKey), &boolValue) && boolValue)
77+
if (ffCfDictGetBool(properties, CFSTR(kIOPMPSAtCriticalLevelKey), &boolValue) == NULL && boolValue)
7478
ffStrbufAppendS(&battery->status, "Critical, ");
7579
ffStrbufTrimRight(&battery->status, ' ');
7680
ffStrbufTrimRight(&battery->status, ',');

0 commit comments

Comments
 (0)