1
0
mirror of synced 2024-12-01 02:37:18 +01:00

impr: Added event logging in debug mode

This commit is contained in:
WerWolv 2023-05-02 20:35:30 +02:00
parent 0c8b3e31e7
commit bec655a8c6
3 changed files with 31 additions and 10 deletions

View File

@ -9,13 +9,20 @@
#include <hex/api/imhex_api.hpp> #include <hex/api/imhex_api.hpp>
#include <hex/helpers/fs.hpp> #include <hex/helpers/fs.hpp>
#include <hex/helpers/logger.hpp>
#define EVENT_DEF(event_name, ...) \ #include <wolv/types/type_name.hpp>
#define EVENT_DEF_IMPL(event_name, should_log, ...) \
struct event_name final : public hex::impl::Event<__VA_ARGS__> { \ struct event_name final : public hex::impl::Event<__VA_ARGS__> { \
constexpr static auto id = [] { return hex::impl::EventId(); }(); \ constexpr static auto Id = [] { return hex::impl::EventId(); }(); \
constexpr static auto ShouldLog = (should_log); \
explicit event_name(Callback func) noexcept : Event(std::move(func)) { } \ explicit event_name(Callback func) noexcept : Event(std::move(func)) { } \
} }
#define EVENT_DEF(event_name, ...) EVENT_DEF_IMPL(event_name, true, __VA_ARGS__)
#define EVENT_DEF_NO_LOG(event_name, ...) EVENT_DEF_IMPL(event_name, false, __VA_ARGS__)
struct GLFWwindow; struct GLFWwindow;
namespace hex { namespace hex {
@ -75,7 +82,7 @@ namespace hex {
*/ */
template<typename E> template<typename E>
static EventList::iterator subscribe(typename E::Callback function) { static EventList::iterator subscribe(typename E::Callback function) {
return s_events.insert(s_events.end(), std::make_pair(E::id, new E(function))); return s_events.insert(s_events.end(), std::make_pair(E::Id, new E(function)));
} }
/** /**
@ -105,7 +112,7 @@ namespace hex {
template<typename E> template<typename E>
static void unsubscribe(void *token) noexcept { static void unsubscribe(void *token) noexcept {
auto iter = std::find_if(s_tokenStore.begin(), s_tokenStore.end(), [&](auto &item) { auto iter = std::find_if(s_tokenStore.begin(), s_tokenStore.end(), [&](auto &item) {
return item.first == token && item.second->first == E::id; return item.first == token && item.second->first == E::Id;
}); });
if (iter != s_tokenStore.end()) { if (iter != s_tokenStore.end()) {
@ -123,11 +130,17 @@ namespace hex {
template<typename E> template<typename E>
static void post(auto &&...args) noexcept { static void post(auto &&...args) noexcept {
for (const auto &[id, event] : s_events) { for (const auto &[id, event] : s_events) {
if (id == E::id) if (id == E::Id) {
(*static_cast<E *const>(event))(std::forward<decltype(args)>(args)...); (*static_cast<E *const>(event))(std::forward<decltype(args)>(args)...);
} }
} }
#if defined (DEBUG)
if (E::ShouldLog)
log::debug("Event posted: '{}'", wolv::type::getTypeName<E>());
#endif
}
/** /**
* @brief Unsubscribe all subscribers from all events * @brief Unsubscribe all subscribers from all events
*/ */
@ -157,10 +170,7 @@ namespace hex {
EVENT_DEF(EventProviderClosed, prv::Provider *); EVENT_DEF(EventProviderClosed, prv::Provider *);
EVENT_DEF(EventProviderDeleted, prv::Provider *); EVENT_DEF(EventProviderDeleted, prv::Provider *);
EVENT_DEF(EventProviderSaved, prv::Provider *); EVENT_DEF(EventProviderSaved, prv::Provider *);
EVENT_DEF(EventFrameBegin);
EVENT_DEF(EventFrameEnd);
EVENT_DEF(EventWindowInitialized); EVENT_DEF(EventWindowInitialized);
EVENT_DEF(EventSetTaskBarIconState, u32, u32, u32);
EVENT_DEF(EventBookmarkCreated, ImHexApi::Bookmarks::Entry&); EVENT_DEF(EventBookmarkCreated, ImHexApi::Bookmarks::Entry&);
EVENT_DEF(EventPatchCreated, u64, u8, u8); EVENT_DEF(EventPatchCreated, u64, u8, u8);
EVENT_DEF(EventPatternExecuted, const std::string&); EVENT_DEF(EventPatternExecuted, const std::string&);
@ -169,6 +179,10 @@ namespace hex {
EVENT_DEF(EventStoreContentRemoved, const std::fs::path&); EVENT_DEF(EventStoreContentRemoved, const std::fs::path&);
EVENT_DEF(EventImHexClosing); EVENT_DEF(EventImHexClosing);
EVENT_DEF_NO_LOG(EventFrameBegin);
EVENT_DEF_NO_LOG(EventFrameEnd);
EVENT_DEF_NO_LOG(EventSetTaskBarIconState, u32, u32, u32);
EVENT_DEF(RequestOpenWindow, std::string); EVENT_DEF(RequestOpenWindow, std::string);
EVENT_DEF(RequestSelectionChange, Region); EVENT_DEF(RequestSelectionChange, Region);
EVENT_DEF(RequestAddBookmark, Region, std::string, std::string, color_t); EVENT_DEF(RequestAddBookmark, Region, std::string, std::string, color_t);

View File

@ -401,7 +401,7 @@ namespace hex {
} }
// Render main menu // Render main menu
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f); ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0F);
if (ImGui::BeginMainMenuBar()) { if (ImGui::BeginMainMenuBar()) {
if (ImHexApi::System::isBorderlessWindowModeEnabled()) { if (ImHexApi::System::isBorderlessWindowModeEnabled()) {

View File

@ -51,6 +51,8 @@ namespace hex::plugin::builtin {
#endif #endif
ContentRegistry::Interface::addFooterItem([] { ContentRegistry::Interface::addFooterItem([] {
static bool shouldResetProgress = false;
auto taskCount = TaskManager::getRunningTaskCount(); auto taskCount = TaskManager::getRunningTaskCount();
if (taskCount > 0) { if (taskCount > 0) {
const auto &tasks = TaskManager::getRunningTasks(); const auto &tasks = TaskManager::getRunningTasks();
@ -103,8 +105,13 @@ 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();
shouldResetProgress = true;
} else { } else {
if (shouldResetProgress) {
ImHexApi::System::setTaskBarProgress(ImHexApi::System::TaskProgressState::Reset, ImHexApi::System::TaskProgressType::Normal, 0); ImHexApi::System::setTaskBarProgress(ImHexApi::System::TaskProgressState::Reset, ImHexApi::System::TaskProgressType::Normal, 0);
shouldResetProgress = false;
}
} }
}); });
} }