feat: Implement messaging support for Linux

This commit is contained in:
WerWolv
2025-01-27 19:07:22 +01:00
parent b2c8ed17d5
commit ef2373e8c0
6 changed files with 92 additions and 53 deletions

View File

@@ -71,9 +71,8 @@ namespace hex {
/**
* @brief Called when a native message was received from another ImHex instance
* @param eventType Type name of the event
* @param args Decoded arguments sent from other instance
* @param rawData Raw bytes received from other instance
*/
EVENT_DEF(EventNativeMessageReceived, std::string, std::vector<u8>);
EVENT_DEF(EventNativeMessageReceived, std::vector<u8>);
}

View File

@@ -866,27 +866,7 @@ namespace hex {
}
extern "C" void macosEventDataReceived(const u8 *data, size_t length) {
ssize_t nullIndex = -1;
auto messageData = reinterpret_cast<const char*>(data);
for (size_t i = 0; i < length; i++) {
if (messageData[i] == '\0') {
nullIndex = i;
break;
}
}
if (nullIndex == -1) {
log::warn("Received invalid forwarded event");
return;
}
std::string eventName(messageData, nullIndex);
std::vector<u8> eventData(messageData + nullIndex + 1, messageData + length);
EventNativeMessageReceived::post(eventName, eventData);
EventNativeMessageReceived::post(std::vector<u8>(data, data + length));
}
}