feat: Implemented macOS messaging support (#2088)

This commit is contained in:
Nik
2025-01-26 18:50:19 +01:00
committed by GitHub
parent 7340a30650
commit bb594a459f
8 changed files with 243 additions and 120 deletions

View File

@@ -26,6 +26,10 @@ namespace hex::messaging {
sendToOtherInstance(eventName, eventData);
}
});
EventNativeMessageReceived::subscribe([](const std::string &eventName, const std::vector<u8> &eventData) {
messageReceived(eventName, eventData);
});
}
void setupMessaging() {

View File

@@ -3,20 +3,30 @@
#include <stdexcept>
#include <hex/helpers/logger.hpp>
#include <hex/helpers/utils_macos.hpp>
#include "messaging.hpp"
namespace hex::messaging {
void sendToOtherInstance(const std::string &eventName, const std::vector<u8> &args) {
std::ignore = eventName;
std::ignore = args;
log::error("Unimplemented function 'sendToOtherInstance()' called");
log::debug("Sending event {} to another instance (not us)", eventName);
// Create the message
std::vector<u8> fullEventData(eventName.begin(), eventName.end());
fullEventData.push_back('\0');
fullEventData.insert(fullEventData.end(), args.begin(), args.end());
u8 *data = &fullEventData[0];
auto dataSize = fullEventData.size();
macosSendMessageToMainInstance(data, dataSize);
}
// Not implemented, so lets say we are the main instance every time so events are forwarded to ourselves
bool setupNative() {
return true;
macosInstallEventListener();
return macosIsMainInstance();
}
}

View File

@@ -42,16 +42,20 @@ namespace hex::messaging {
log::debug("Sending event {} to another instance (not us)", eventName);
// Get the window we want to send it to
HWND imHexWindow = *getImHexWindow();
auto potentialWindow = getImHexWindow();
if (!potentialWindow.has_value())
return;
HWND imHexWindow = potentialWindow.value();
// Create the message
std::vector<u8> fulleventData(eventName.begin(), eventName.end());
fulleventData.push_back('\0');
std::vector<u8> fullEventData(eventName.begin(), eventName.end());
fullEventData.push_back('\0');
fulleventData.insert(fulleventData.end(), args.begin(), args.end());
fullEventData.insert(fullEventData.end(), args.begin(), args.end());
u8 *data = &fulleventData[0];
DWORD dataSize = fulleventData.size();
u8 *data = &fullEventData[0];
DWORD dataSize = fullEventData.size();
COPYDATASTRUCT message = {
.dwData = 0,