1
0
mirror of synced 2024-09-24 11:38:26 +02:00

ui: Show task progress in task bar

This commit is contained in:
WerWolv 2023-01-14 14:21:16 +01:00
parent f7e22ce651
commit 1b56c7ffae
6 changed files with 65 additions and 8 deletions

View File

@ -121,6 +121,7 @@ namespace hex {
EVENT_DEF(EventFrameBegin);
EVENT_DEF(EventFrameEnd);
EVENT_DEF(EventWindowInitialized);
EVENT_DEF(EventSetTaskBarIconState, u32, u32, u32);
EVENT_DEF(RequestOpenWindow, std::string);
EVENT_DEF(RequestSelectionChange, Region);

View File

@ -191,6 +191,20 @@ namespace hex {
char **envp;
};
enum class TaskProgressState {
Reset,
Progress,
Flash
};
enum class TaskProgressType {
Normal,
Warning,
Error
};
void setTaskBarProgress(TaskProgressState state, TaskProgressType type, u32 progress);
const ProgramArguments &getProgramArguments();
std::optional<std::u8string> getProgramArgument(int index);

View File

@ -409,6 +409,10 @@ namespace hex {
}
void setTaskBarProgress(TaskProgressState state, TaskProgressType type, u32 progress) {
EventManager::post<EventSetTaskBarIconState>(u32(state), u32(type), progress);
}
const ProgramArguments &getProgramArguments() {
return impl::s_programArguments;
}

View File

@ -2,7 +2,6 @@
#include <hex/helpers/utils.hpp>
#include <hex/helpers/logger.hpp>
#include <hex/api/theme_manager.hpp>
#include "window.hpp"
@ -15,10 +14,6 @@ int main(int argc, char **argv, char **envp) {
using namespace hex;
ImHexApi::System::impl::setProgramArguments(argc, argv, envp);
#if defined(OS_WINDOWS)
ImHexApi::System::impl::setBorderlessWindowMode(true);
#endif
bool shouldRestart = false;
do {

View File

@ -11,8 +11,6 @@
#include <imgui_internal.h>
#include <fonts/codicons_font.h>
#include <nlohmann/json.hpp>
#include <GLFW/glfw3.h>
#define GLFW_EXPOSE_NATIVE_WIN32
#include <GLFW/glfw3native.h>
@ -22,6 +20,8 @@
#include <winuser.h>
#include <dwmapi.h>
#include <windowsx.h>
#include <shobjidl.h>
#include <wrl/client.h>
#include <csignal>
@ -32,6 +32,7 @@ namespace hex {
static LONG_PTR g_oldWndProc;
static float g_titleBarHeight;
static ImGuiMouseCursor g_mouseCursorIcon;
static Microsoft::WRL::ComPtr<ITaskbarList4> g_taskbarList;
static LRESULT commonWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
switch (uMsg) {
@ -188,6 +189,7 @@ namespace hex {
void Window::initNative() {
ImHexApi::System::impl::setBorderlessWindowMode(true);
// Add plugin library folders to dll search path
for (const auto &path : hex::fs::getDefaultPaths(fs::ImHexPath::Libraries)) {
@ -299,6 +301,41 @@ namespace hex {
return EXCEPTION_CONTINUE_SEARCH;
});
}
if (SUCCEEDED(CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED))) {
CoCreateInstance(CLSID_TaskbarList, nullptr, CLSCTX_INPROC_SERVER, IID_ITaskbarList4, &g_taskbarList);
}
EventManager::subscribe<EventSetTaskBarIconState>([hwnd](u32 state, u32 type, u32 progress){
using enum ImHexApi::System::TaskProgressState;
switch (ImHexApi::System::TaskProgressState(state)) {
case Reset:
g_taskbarList->SetProgressState(hwnd, TBPF_NOPROGRESS);
g_taskbarList->SetProgressValue(hwnd, 0, 0);
break;
case Flash:
FlashWindow(hwnd, true);
break;
case Progress:
g_taskbarList->SetProgressState(hwnd, TBPF_INDETERMINATE);
g_taskbarList->SetProgressValue(hwnd, progress, 100);
break;
}
using enum ImHexApi::System::TaskProgressType;
switch (ImHexApi::System::TaskProgressType(type)) {
case Normal:
g_taskbarList->SetProgressState(hwnd, TBPF_NORMAL);
break;
case Warning:
g_taskbarList->SetProgressState(hwnd, TBPF_PAUSED);
break;
case Error:
g_taskbarList->SetProgressState(hwnd, TBPF_ERROR);
break;
}
});
}
void Window::beginNativeWindowFrame() {

View File

@ -230,11 +230,15 @@ namespace hex::plugin::builtin {
auto &tasks = TaskManager::getRunningTasks();
auto frontTask = tasks.front();
auto progress = float(frontTask->getValue()) / frontTask->getMaxValue();
ImHexApi::System::setTaskBarProgress(ImHexApi::System::TaskProgressState::Progress, ImHexApi::System::TaskProgressType::Normal, progress * 100);
auto widgetStart = ImGui::GetCursorPos();
ImGui::TextSpinner(hex::format("({})", taskCount).c_str());
ImGui::SameLine();
ImGui::SmallProgressBar(frontTask->getMaxValue() == 0 ? 1 : (float(frontTask->getValue()) / frontTask->getMaxValue()), (ImGui::GetCurrentWindow()->MenuBarHeight() - 10_scaled) / 2.0);
ImGui::SmallProgressBar(frontTask->getMaxValue() == 0 ? 1 : progress, (ImGui::GetCurrentWindow()->MenuBarHeight() - 10_scaled) / 2.0);
ImGui::SameLine();
auto widgetEnd = ImGui::GetCursorPos();
@ -273,6 +277,8 @@ namespace hex::plugin::builtin {
if (ImGui::ToolBarButton(ICON_VS_DEBUG_STOP, ImGui::GetStyleColorVec4(ImGuiCol_Text)))
frontTask->interrupt();
ImGui::PopStyleVar();
} else {
ImHexApi::System::setTaskBarProgress(ImHexApi::System::TaskProgressState::Reset, ImHexApi::System::TaskProgressType::Normal, 0);
}
});
}