fix macos battery detection

This commit is contained in:
Jethro Grassie 2020-08-11 17:52:26 -04:00
parent a0fe49f946
commit b78b0b5c6b
No known key found for this signature in database
GPG key ID: DE8ED755616565BB
2 changed files with 5 additions and 11 deletions

View file

@ -143,6 +143,8 @@ elseif (XMRIG_OS_APPLE)
src/App_unix.cpp src/App_unix.cpp
src/crypto/common/VirtualMemory_unix.cpp src/crypto/common/VirtualMemory_unix.cpp
) )
find_library(IOKIT_LIBRARY IOKit)
set(EXTRA_LIBS ${IOKIT_LIBRARY})
else() else()
list(APPEND SOURCES_OS list(APPEND SOURCES_OS
src/App_unix.cpp src/App_unix.cpp

View file

@ -22,6 +22,8 @@
*/ */
#include <IOKit/IOKitLib.h>
#include <IOKit/ps/IOPowerSources.h>
#include <mach/thread_act.h> #include <mach/thread_act.h>
#include <mach/thread_policy.h> #include <mach/thread_policy.h>
#include <stdio.h> #include <stdio.h>
@ -111,15 +113,5 @@ void xmrig::Platform::setThreadPriority(int priority)
bool xmrig::Platform::isOnBatteryPower() bool xmrig::Platform::isOnBatteryPower()
{ {
for (int i = 0; i <= 1; ++i) { return IOPSGetTimeRemainingEstimate() != kIOPSTimeRemainingUnlimited;
char buf[64];
snprintf(buf, 64, "/sys/class/power_supply/BAT%d/status", i);
std::ifstream f(buf);
if (f.is_open()) {
std::string status;
f >> status;
return (status == "Discharging");
}
}
return false;
} }