From d862ba853f7eb5119082001ada115ffe08684c3a Mon Sep 17 00:00:00 2001 From: XMRig Date: Tue, 16 Aug 2022 17:31:39 +0700 Subject: [PATCH] Revert Taskbar class. --- CMakeLists.txt | 4 +- src/core/Miner.cpp | 17 +++--- src/core/Taskbar.cpp | 126 +++++++++++++++++++++++++++++++++++++++++++ src/core/Taskbar.h | 51 ++++++++++++++++++ 4 files changed, 187 insertions(+), 11 deletions(-) create mode 100644 src/core/Taskbar.cpp create mode 100644 src/core/Taskbar.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 74c39477..765109dd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/src/core/Miner.cpp b/src/core/Miner.cpp index 79b5b749..a55f0b32 100644 --- a/src/core/Miner.cpp +++ b/src/core/Miner.cpp @@ -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 maxHashrate; std::vector 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(); diff --git a/src/core/Taskbar.cpp b/src/core/Taskbar.cpp new file mode 100644 index 00000000..89a2e848 --- /dev/null +++ b/src/core/Taskbar.cpp @@ -0,0 +1,126 @@ +/* XMRig + * Copyright (c) 2018-2022 SChernykh + * Copyright (c) 2016-2022 XMRig , + * + * 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 . + */ + +#include "core/Taskbar.h" + +#ifdef _WIN32 + + +#include +#include + + +namespace xmrig { + + +struct TaskbarPrivate +{ + TaskbarPrivate() + { + HRESULT hr = CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED); + if (hr < 0) { + return; + } + + hr = CoCreateInstance(CLSID_TaskbarList, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&m_taskbar)); + if (hr < 0) { + return; + } + + hr = m_taskbar->HrInit(); + if (hr < 0) { + m_taskbar->Release(); + m_taskbar = nullptr; + return; + } + + m_consoleWnd = GetConsoleWindow(); + } + + ~TaskbarPrivate() + { + if (m_taskbar) { + m_taskbar->Release(); + } + CoUninitialize(); + } + + ITaskbarList3* m_taskbar = nullptr; + HWND m_consoleWnd = nullptr; +}; + + +Taskbar::Taskbar() : d_ptr(new TaskbarPrivate()) +{ +} + + +Taskbar::~Taskbar() +{ + delete d_ptr; +} + + +void Taskbar::setActive(bool active) +{ + m_active = active; + updateTaskbarColor(); +} + + +void Taskbar::setEnabled(bool enabled) +{ + m_enabled = enabled; + updateTaskbarColor(); +} + + +void Taskbar::updateTaskbarColor() +{ + if (d_ptr->m_taskbar) { + if (m_active) { + d_ptr->m_taskbar->SetProgressState(d_ptr->m_consoleWnd, m_enabled ? TBPF_NOPROGRESS : TBPF_PAUSED); + d_ptr->m_taskbar->SetProgressValue(d_ptr->m_consoleWnd, m_enabled ? 0 : 1, 1); + } + else { + d_ptr->m_taskbar->SetProgressState(d_ptr->m_consoleWnd, TBPF_ERROR); + d_ptr->m_taskbar->SetProgressValue(d_ptr->m_consoleWnd, 1, 1); + } + } +} + + +} // namespace xmrig + + +#else // _WIN32 + + +namespace xmrig { + + +Taskbar::Taskbar() {} +Taskbar::~Taskbar() {} +void Taskbar::setActive(bool) {} +void Taskbar::setEnabled(bool) {} + + +} // namespace xmrig + + +#endif // _WIN32 diff --git a/src/core/Taskbar.h b/src/core/Taskbar.h new file mode 100644 index 00000000..7b5f110b --- /dev/null +++ b/src/core/Taskbar.h @@ -0,0 +1,51 @@ +/* XMRig + * Copyright (c) 2018-2022 SChernykh + * Copyright (c) 2016-2022 XMRig , + * + * 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 . + */ + +#ifndef XMRIG_TASKBAR_H +#define XMRIG_TASKBAR_H + + +namespace xmrig { + + +struct TaskbarPrivate; + + +class Taskbar +{ +public: + Taskbar(); + ~Taskbar(); + + void setActive(bool active); + void setEnabled(bool enabled); + +private: + bool m_active = false; + bool m_enabled = true; + + TaskbarPrivate* d_ptr = nullptr; + + void updateTaskbarColor(); +}; + + +} // namespace xmrig + + +#endif /* XMRIG_TASKBAR_H */