Skip to content

Commit 7f19cb1

Browse files
committed
Battery: print error info instead of nan% ( macOS )
1 parent e605375 commit 7f19cb1

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/detection/battery/battery_apple.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,23 @@ const char* ffDetectBatteryImpl(FFinstance* instance, FFlist* results)
2727
}
2828

2929
bool boolValue;
30+
const char* error;
3031

3132
BatteryResult* battery = ffListAdd(results);
3233
ffStrbufInit(&battery->capacity);
3334
int currentCapacity, maxCapacity;
34-
if(!ffCfDictGetInt(properties, CFSTR("CurrentCapacity"), &currentCapacity) &&
35-
!ffCfDictGetInt(properties, CFSTR("MaxCapacity"), &maxCapacity))
36-
ffStrbufAppendF(&battery->capacity, "%.0f", currentCapacity * 100.0 / maxCapacity);
35+
36+
if ((error = ffCfDictGetInt(properties, CFSTR("MaxCapacity"), &maxCapacity)))
37+
return error;
38+
if (maxCapacity <= 0)
39+
return "Querying MaxCapacity failed";
40+
41+
if ((error = ffCfDictGetInt(properties, CFSTR("CurrentCapacity"), &currentCapacity)))
42+
return error;
43+
if(currentCapacity <= 0)
44+
return "Querying CurrentCapacity failed";
45+
46+
ffStrbufAppendF(&battery->capacity, "%.0f", currentCapacity * 100.0 / maxCapacity);
3747

3848
ffStrbufInit(&battery->manufacturer);
3949
ffStrbufInit(&battery->modelName);

0 commit comments

Comments
 (0)