2023-07-13 14:08:23 +02:00
|
|
|
#include <optional>
|
|
|
|
|
|
|
|
#include <hex/api/imhex_api.hpp>
|
2023-11-18 14:50:43 +01:00
|
|
|
#include <hex/api/event_manager.hpp>
|
2023-07-13 14:08:23 +02:00
|
|
|
#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);
|
2023-07-13 14:08:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void setupEvents() {
|
2023-12-08 10:29:44 +01:00
|
|
|
SendMessageToMainInstance::subscribe([](const std::string &eventName, const std::vector<u8> &eventData) {
|
2023-07-13 14:08:23 +02:00
|
|
|
log::debug("Forwarding message {} (maybe to us)", eventName);
|
|
|
|
if (ImHexApi::System::isMainInstance()) {
|
2023-12-08 10:29:44 +01:00
|
|
|
EventImHexStartupFinished::subscribe([eventName, eventData]{
|
2023-07-13 14:08:23 +02:00
|
|
|
ImHexApi::Messaging::impl::runHandler(eventName, eventData);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
sendToOtherInstance(eventName, eventData);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void setupMessaging() {
|
|
|
|
ImHexApi::System::impl::setMainInstanceStatus(setupNative());
|
|
|
|
setupEvents();
|
|
|
|
}
|
|
|
|
}
|