1
0
mirror of https://github.com/xmrig/xmrig.git synced 2025-12-06 15:42:38 -05:00

Compare commits

...

2 Commits

Author SHA1 Message Date
XMRig
4fec1b0aed Taskbar class cleanup. 2022-08-16 17:54:33 +07:00
XMRig
d862ba853f Revert Taskbar class. 2022-08-16 17:31:39 +07:00
4 changed files with 185 additions and 11 deletions

View File

@@ -41,7 +41,7 @@ add_definitions(-DXMRIG_MINER_PROJECT)
set(WITH_SODIUM OFF)
set(WITH_CRYPTONOTE ON)
set(WITH_CRYPTO_OPS ON)
set(WITH_COM ON)
set(WITH_COM OFF)
set(WITH_EVENTS OFF)
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/src/base/cmake" "${CMAKE_SOURCE_DIR}/cmake")
@@ -63,6 +63,7 @@ set(HEADERS
src/core/config/usage.h
src/core/Controller.h
src/core/Miner.h
src/core/Taskbar.h
src/crypto/cn/asm/CryptonightR_template.h
src/crypto/cn/c_blake256.h
src/crypto/cn/c_groestl.h
@@ -105,6 +106,7 @@ set(SOURCES
src/core/config/ConfigTransform.cpp
src/core/Controller.cpp
src/core/Miner.cpp
src/core/Taskbar.cpp
src/crypto/cn/c_blake256.c
src/crypto/cn/c_groestl.c
src/crypto/cn/c_jh.c

View File

@@ -30,12 +30,12 @@
#include "base/io/log/Tags.h"
#include "base/kernel/OS.h"
#include "base/kernel/Process.h"
#include "base/kernel/Taskbar.h"
#include "base/net/stratum/Job.h"
#include "base/tools/Object.h"
#include "base/tools/Timer.h"
#include "core/config/Config.h"
#include "core/Controller.h"
#include "core/Taskbar.h"
#include "crypto/common/Nonce.h"
#include "version.h"
@@ -358,21 +358,18 @@ public:
Algorithms algorithms;
bool active = false;
bool battery_power = false;
bool user_active = false;
bool enabled = true;
int32_t auto_pause = 0;
bool reset = true;
bool user_active = false;
Controller *controller;
int32_t auto_pause = 0;
Job job;
mutable std::map<Algorithm::Id, double> maxHashrate;
std::vector<IBackend *> backends;
String userJobId;
Taskbar taskbar;
Timer *timer = nullptr;
uint64_t ticks = 0;
# ifdef XMRIG_FEATURE_COM
Taskbar m_taskbar;
# endif
};
@@ -496,7 +493,7 @@ void xmrig::Miner::execCommand(char command)
void xmrig::Miner::pause()
{
d_ptr->active = false;
// d_ptr->m_taskbar.setActive(false); // FIXME
d_ptr->taskbar.setActive(false);
Nonce::pause(true);
Nonce::touch();
@@ -516,7 +513,7 @@ void xmrig::Miner::setEnabled(bool enabled)
}
d_ptr->enabled = enabled;
// d_ptr->m_taskbar.setEnabled(enabled); // FIXME
d_ptr->taskbar.setEnabled(enabled);
if (enabled) {
LOG_INFO("%s " GREEN_BOLD("resumed"), Tags::miner());
@@ -586,7 +583,7 @@ void xmrig::Miner::setJob(const Job &job, bool donate)
mutex.unlock();
d_ptr->active = true;
// d_ptr->m_taskbar.setActive(true); // FIXME
d_ptr->taskbar.setActive(true);
if (ready) {
d_ptr->handleJobChange();

125
src/core/Taskbar.cpp Normal file
View File

@@ -0,0 +1,125 @@
/* XMRig
* Copyright (c) 2018-2022 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2022 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "core/Taskbar.h"
#ifdef _WIN32
#include <Shobjidl.h>
#include <Objbase.h>
namespace xmrig {
class Taskbar::Private
{
public:
XMRIG_DISABLE_COPY_MOVE(Private)
Private()
{
HRESULT hr = CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED);
if (hr < 0) {
return;
}
hr = CoCreateInstance(CLSID_TaskbarList, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&taskbar));
if (hr < 0) {
return;
}
hr = taskbar->HrInit();
if (hr < 0) {
taskbar->Release();
taskbar = nullptr;
return;
}
console = GetConsoleWindow();
}
~Private()
{
if (taskbar) {
taskbar->Release();
}
CoUninitialize();
}
void update()
{
if (taskbar) {
if (active) {
taskbar->SetProgressState(console, enabled ? TBPF_NOPROGRESS : TBPF_PAUSED);
taskbar->SetProgressValue(console, enabled ? 0 : 1, 1);
}
else {
taskbar->SetProgressState(console, TBPF_ERROR);
taskbar->SetProgressValue(console, 1, 1);
}
}
}
bool active = false;
bool enabled = true;
HWND console = nullptr;
ITaskbarList3 *taskbar = nullptr;
};
Taskbar::Taskbar() :
d(std::make_shared<Private>())
{
}
void Taskbar::setActive(bool active)
{
d->active = active;
d->update();
}
void Taskbar::setEnabled(bool enabled)
{
d->enabled = enabled;
d->update();
}
} // namespace xmrig
#else // _WIN32
namespace xmrig {
Taskbar::Taskbar() = default;
void Taskbar::setActive(bool) {}
void Taskbar::setEnabled(bool) {}
} // namespace xmrig
#endif // _WIN32

50
src/core/Taskbar.h Normal file
View File

@@ -0,0 +1,50 @@
/* XMRig
* Copyright (c) 2018-2022 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2022 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef XMRIG_TASKBAR_H
#define XMRIG_TASKBAR_H
#include "base/tools/Object.h"
namespace xmrig {
class Taskbar
{
public:
XMRIG_DISABLE_COPY_MOVE(Taskbar)
Taskbar();
~Taskbar() = default;
void setActive(bool active);
void setEnabled(bool enabled);
private:
# ifdef _WIN32
XMRIG_DECL_PRIVATE()
# endif
};
} // namespace xmrig
#endif // XMRIG_TASKBAR_H