ui: Show task progress in task bar
This commit is contained in:
parent
f7e22ce651
commit
1b56c7ffae
@ -121,6 +121,7 @@ namespace hex {
|
|||||||
EVENT_DEF(EventFrameBegin);
|
EVENT_DEF(EventFrameBegin);
|
||||||
EVENT_DEF(EventFrameEnd);
|
EVENT_DEF(EventFrameEnd);
|
||||||
EVENT_DEF(EventWindowInitialized);
|
EVENT_DEF(EventWindowInitialized);
|
||||||
|
EVENT_DEF(EventSetTaskBarIconState, u32, u32, u32);
|
||||||
|
|
||||||
EVENT_DEF(RequestOpenWindow, std::string);
|
EVENT_DEF(RequestOpenWindow, std::string);
|
||||||
EVENT_DEF(RequestSelectionChange, Region);
|
EVENT_DEF(RequestSelectionChange, Region);
|
||||||
|
@ -191,6 +191,20 @@ namespace hex {
|
|||||||
char **envp;
|
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();
|
const ProgramArguments &getProgramArguments();
|
||||||
std::optional<std::u8string> getProgramArgument(int index);
|
std::optional<std::u8string> getProgramArgument(int index);
|
||||||
|
|
||||||
|
@ -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() {
|
const ProgramArguments &getProgramArguments() {
|
||||||
return impl::s_programArguments;
|
return impl::s_programArguments;
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
#include <hex/helpers/utils.hpp>
|
#include <hex/helpers/utils.hpp>
|
||||||
#include <hex/helpers/logger.hpp>
|
#include <hex/helpers/logger.hpp>
|
||||||
#include <hex/api/theme_manager.hpp>
|
|
||||||
|
|
||||||
#include "window.hpp"
|
#include "window.hpp"
|
||||||
|
|
||||||
@ -15,10 +14,6 @@ int main(int argc, char **argv, char **envp) {
|
|||||||
using namespace hex;
|
using namespace hex;
|
||||||
ImHexApi::System::impl::setProgramArguments(argc, argv, envp);
|
ImHexApi::System::impl::setProgramArguments(argc, argv, envp);
|
||||||
|
|
||||||
#if defined(OS_WINDOWS)
|
|
||||||
ImHexApi::System::impl::setBorderlessWindowMode(true);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
bool shouldRestart = false;
|
bool shouldRestart = false;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
|
@ -11,8 +11,6 @@
|
|||||||
#include <imgui_internal.h>
|
#include <imgui_internal.h>
|
||||||
#include <fonts/codicons_font.h>
|
#include <fonts/codicons_font.h>
|
||||||
|
|
||||||
#include <nlohmann/json.hpp>
|
|
||||||
|
|
||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
#define GLFW_EXPOSE_NATIVE_WIN32
|
#define GLFW_EXPOSE_NATIVE_WIN32
|
||||||
#include <GLFW/glfw3native.h>
|
#include <GLFW/glfw3native.h>
|
||||||
@ -22,6 +20,8 @@
|
|||||||
#include <winuser.h>
|
#include <winuser.h>
|
||||||
#include <dwmapi.h>
|
#include <dwmapi.h>
|
||||||
#include <windowsx.h>
|
#include <windowsx.h>
|
||||||
|
#include <shobjidl.h>
|
||||||
|
#include <wrl/client.h>
|
||||||
|
|
||||||
#include <csignal>
|
#include <csignal>
|
||||||
|
|
||||||
@ -32,6 +32,7 @@ namespace hex {
|
|||||||
static LONG_PTR g_oldWndProc;
|
static LONG_PTR g_oldWndProc;
|
||||||
static float g_titleBarHeight;
|
static float g_titleBarHeight;
|
||||||
static ImGuiMouseCursor g_mouseCursorIcon;
|
static ImGuiMouseCursor g_mouseCursorIcon;
|
||||||
|
static Microsoft::WRL::ComPtr<ITaskbarList4> g_taskbarList;
|
||||||
|
|
||||||
static LRESULT commonWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
|
static LRESULT commonWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
|
||||||
switch (uMsg) {
|
switch (uMsg) {
|
||||||
@ -188,6 +189,7 @@ namespace hex {
|
|||||||
|
|
||||||
|
|
||||||
void Window::initNative() {
|
void Window::initNative() {
|
||||||
|
ImHexApi::System::impl::setBorderlessWindowMode(true);
|
||||||
|
|
||||||
// Add plugin library folders to dll search path
|
// Add plugin library folders to dll search path
|
||||||
for (const auto &path : hex::fs::getDefaultPaths(fs::ImHexPath::Libraries)) {
|
for (const auto &path : hex::fs::getDefaultPaths(fs::ImHexPath::Libraries)) {
|
||||||
@ -299,6 +301,41 @@ namespace hex {
|
|||||||
return EXCEPTION_CONTINUE_SEARCH;
|
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() {
|
void Window::beginNativeWindowFrame() {
|
||||||
|
@ -230,11 +230,15 @@ namespace hex::plugin::builtin {
|
|||||||
auto &tasks = TaskManager::getRunningTasks();
|
auto &tasks = TaskManager::getRunningTasks();
|
||||||
auto frontTask = tasks.front();
|
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();
|
auto widgetStart = ImGui::GetCursorPos();
|
||||||
|
|
||||||
ImGui::TextSpinner(hex::format("({})", taskCount).c_str());
|
ImGui::TextSpinner(hex::format("({})", taskCount).c_str());
|
||||||
ImGui::SameLine();
|
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();
|
ImGui::SameLine();
|
||||||
|
|
||||||
auto widgetEnd = ImGui::GetCursorPos();
|
auto widgetEnd = ImGui::GetCursorPos();
|
||||||
@ -273,6 +277,8 @@ namespace hex::plugin::builtin {
|
|||||||
if (ImGui::ToolBarButton(ICON_VS_DEBUG_STOP, ImGui::GetStyleColorVec4(ImGuiCol_Text)))
|
if (ImGui::ToolBarButton(ICON_VS_DEBUG_STOP, ImGui::GetStyleColorVec4(ImGuiCol_Text)))
|
||||||
frontTask->interrupt();
|
frontTask->interrupt();
|
||||||
ImGui::PopStyleVar();
|
ImGui::PopStyleVar();
|
||||||
|
} else {
|
||||||
|
ImHexApi::System::setTaskBarProgress(ImHexApi::System::TaskProgressState::Reset, ImHexApi::System::TaskProgressType::Normal, 0);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user