1
0
mirror of synced 2024-12-21 03:55:56 +01:00
ImHex/main/gui/source/messaging/common.cpp

34 lines
1.1 KiB
C++
Raw Normal View History

#include <optional>
#include <hex/api/imhex_api.hpp>
#include <hex/api/event_manager.hpp>
#include <hex/helpers/logger.hpp>
#include "messaging.hpp"
namespace hex::messaging {
2023-11-10 20:47:08 +01:00
void messageReceived(const std::string &eventName, const std::vector<u8> &args) {
log::debug("Received event '{}' with size {}", eventName, args.size());
ImHexApi::Messaging::impl::runHandler(eventName, args);
}
void setupEvents() {
SendMessageToMainInstance::subscribe([](const std::string &eventName, const std::vector<u8> &eventData) {
log::debug("Forwarding message {} (maybe to us)", eventName);
if (ImHexApi::System::isMainInstance()) {
EventImHexStartupFinished::subscribe([eventName, eventData]{
ImHexApi::Messaging::impl::runHandler(eventName, eventData);
});
} else {
sendToOtherInstance(eventName, eventData);
}
});
}
void setupMessaging() {
ImHexApi::System::impl::setMainInstanceStatus(setupNative());
setupEvents();
}
}