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

@ -352,6 +352,7 @@ public:
Algorithms algorithms;
bool active = false;
bool battery_power = false;
bool user_active = false;
bool enabled = true;
bool reset = true;
Controller *controller;
@ -629,18 +630,32 @@ void xmrig::Miner::onTimer(const Timer *)
if (d_ptr->controller->config()->isPauseOnBattery()) {
const bool battery_power = Platform::isOnBatteryPower();
if (battery_power && d_ptr->enabled) {
if (battery_power && !d_ptr->battery_power) {
LOG_INFO("%s " YELLOW_BOLD("on battery power"), Tags::miner());
d_ptr->battery_power = true;
setEnabled(false);
}
else if (!battery_power && !d_ptr->enabled && d_ptr->battery_power) {
else if (!battery_power && d_ptr->battery_power) {
LOG_INFO("%s " GREEN_BOLD("on AC power"), Tags::miner());
d_ptr->battery_power = false;
setEnabled(true);
}
}
if (d_ptr->controller->config()->isPauseOnActive()) {
const bool user_active = Platform::isUserActive();
if (user_active && !d_ptr->user_active) {
LOG_INFO("%s " YELLOW_BOLD("user active"), Tags::miner());
d_ptr->user_active = true;
}
else if (!user_active && d_ptr->user_active) {
LOG_INFO("%s " GREEN_BOLD("user inactive"), Tags::miner());
d_ptr->user_active = false;
}
}
const bool batteryEnabled = !(d_ptr->controller->config()->isPauseOnBattery() && d_ptr->battery_power);
const bool userActiveEnabled = !(d_ptr->controller->config()->isPauseOnActive() && d_ptr->user_active);
setEnabled(batteryEnabled && userActiveEnabled);
if (stopMiner) {
stop();
}

View file

@ -270,4 +270,5 @@ void xmrig::Config::getJSON(rapidjson::Document &doc) const
doc.AddMember(StringRef(kVerbose), Log::verbose(), allocator);
doc.AddMember(StringRef(kWatch), m_watch, allocator);
doc.AddMember(StringRef(kPauseOnBattery), isPauseOnBattery(), allocator);
doc.AddMember(StringRef(kPauseOnActive), isPauseOnActive(), allocator);
}

View file

@ -126,7 +126,8 @@ R"===(
"user-agent": null,
"verbose": 0,
"watch": true,
"pause-on-battery": false
"pause-on-battery": false,
"pause-on-active": false
}
)===";
#endif

View file

@ -98,6 +98,7 @@ static const option options[] = {
{ "title", 1, nullptr, IConfig::TitleKey },
{ "no-title", 0, nullptr, IConfig::NoTitleKey },
{ "pause-on-battery", 0, nullptr, IConfig::PauseOnBatteryKey },
{ "pause-on-active", 0, nullptr, IConfig::PauseOnActiveKey },
# ifdef XMRIG_FEATURE_BENCHMARK
{ "stress", 0, nullptr, IConfig::StressKey },
{ "bench", 1, nullptr, IConfig::BenchKey },

View file

@ -181,6 +181,7 @@ static inline const std::string &usage()
u += " --no-title disable setting console window title\n";
# endif
u += " --pause-on-battery pause mine on battery power\n";
u += " --pause-on-active pause mine when mouse or keyboard is touched\n";
# ifdef XMRIG_FEATURE_BENCHMARK
u += " --stress run continuous stress test to check system stability\n";