Added pause-on-active option

Windows only for now. When set to true, pauses mining when user touches mouse or keyboard.
This commit is contained in:
SChernykh 2021-02-14 15:32:18 +01:00
parent 8e3fec5768
commit 82830e359a
13 changed files with 57 additions and 6 deletions

View file

@ -49,6 +49,7 @@ public:
static inline const String &userAgent() { return m_userAgent; }
static bool isOnBatteryPower();
static bool isUserActive();
private:
static char *createUserAgent();

View file

@ -158,3 +158,10 @@ bool xmrig::Platform::isOnBatteryPower()
}
return false;
}
bool xmrig::Platform::isUserActive()
{
// TODO
return false;
}

View file

@ -161,3 +161,16 @@ bool xmrig::Platform::isOnBatteryPower()
}
return false;
}
bool xmrig::Platform::isUserActive()
{
LASTINPUTINFO info;
info.cbSize = sizeof(LASTINPUTINFO);
if (!GetLastInputInfo(&info)) {
return false;
}
return static_cast<int>(GetTickCount() - info.dwTime) < 60 * 1000;
}

View file

@ -62,6 +62,7 @@ const char *BaseConfig::kDryRun = "dry-run";
const char *BaseConfig::kHttp = "http";
const char *BaseConfig::kLogFile = "log-file";
const char *BaseConfig::kPauseOnBattery = "pause-on-battery";
const char *BaseConfig::kPauseOnActive = "pause-on-active";
const char *BaseConfig::kPrintTime = "print-time";
const char *BaseConfig::kSyslog = "syslog";
const char *BaseConfig::kTitle = "title";
@ -92,6 +93,7 @@ bool xmrig::BaseConfig::read(const IJsonReader &reader, const char *fileName)
m_syslog = reader.getBool(kSyslog, m_syslog);
m_watch = reader.getBool(kWatch, m_watch);
m_pauseOnBattery = reader.getBool(kPauseOnBattery, m_pauseOnBattery);
m_pauseOnActive = reader.getBool(kPauseOnActive, m_pauseOnActive);
m_logFile = reader.getString(kLogFile);
m_userAgent = reader.getString(kUserAgent);
m_printTime = std::min(reader.getUint(kPrintTime, m_printTime), 3600U);

View file

@ -56,6 +56,7 @@ public:
static const char *kHttp;
static const char *kLogFile;
static const char *kPauseOnBattery;
static const char *kPauseOnActive;
static const char *kPrintTime;
static const char *kSyslog;
static const char *kTitle;
@ -73,6 +74,7 @@ public:
inline bool isBackground() const { return m_background; }
inline bool isDryRun() const { return m_dryRun; }
inline bool isPauseOnBattery() const { return m_pauseOnBattery; }
inline bool isPauseOnActive() const { return m_pauseOnActive; }
inline bool isSyslog() const { return m_syslog; }
inline const char *logFile() const { return m_logFile.data(); }
inline const char *userAgent() const { return m_userAgent.data(); }
@ -101,6 +103,7 @@ protected:
bool m_background = false;
bool m_dryRun = false;
bool m_pauseOnBattery = false;
bool m_pauseOnActive = false;
bool m_syslog = false;
bool m_upgrade = false;
bool m_watch = true;

View file

@ -262,6 +262,7 @@ void xmrig::BaseTransform::transform(rapidjson::Document &doc, int key, const ch
case IConfig::DaemonKey: /* --daemon */
case IConfig::VerboseKey: /* --verbose */
case IConfig::PauseOnBatteryKey: /* --pause-on-battery */
case IConfig::PauseOnActiveKey: /* --pause-on-active */
return transformBoolean(doc, key, true);
case IConfig::ColorKey: /* --no-color */
@ -323,6 +324,9 @@ void xmrig::BaseTransform::transformBoolean(rapidjson::Document &doc, int key, b
case IConfig::PauseOnBatteryKey: /* --pause-on-battery */
return set(doc, BaseConfig::kPauseOnBattery, enable);
case IConfig::PauseOnActiveKey: /* --pause-on-active */
return set(doc, BaseConfig::kPauseOnActive, enable);
default:
break;
}

View file

@ -86,6 +86,7 @@ public:
BenchTokenKey = 1048,
DmiKey = 1049,
HugePageSizeKey = 1050,
PauseOnActiveKey = 1051,
// xmrig common
CPUPriorityKey = 1021,