2022-11-28 12:45:23 -05:00
|
|
|
#include <InternalLoader.hpp>
|
2022-11-22 10:21:00 -05:00
|
|
|
#include <Geode/loader/Log.hpp>
|
|
|
|
#include <iostream>
|
2022-11-28 12:45:23 -05:00
|
|
|
#include <InternalMod.hpp>
|
2022-11-30 11:51:38 -05:00
|
|
|
#include <Geode/loader/IPC.hpp>
|
2022-11-22 10:21:00 -05:00
|
|
|
|
|
|
|
#ifdef GEODE_IS_MACOS
|
|
|
|
|
|
|
|
#include <CoreFoundation/CoreFoundation.h>
|
|
|
|
|
|
|
|
void InternalLoader::platformMessageBox(char const* title, std::string const& info) {
|
|
|
|
CFStringRef cfTitle = CFStringCreateWithCString(NULL, title, kCFStringEncodingUTF8);
|
|
|
|
CFStringRef cfMessage = CFStringCreateWithCString(NULL, info.c_str(), kCFStringEncodingUTF8);
|
|
|
|
|
|
|
|
CFUserNotificationDisplayNotice(
|
|
|
|
0, kCFUserNotificationNoteAlertLevel, NULL, NULL, NULL, cfTitle, cfMessage, NULL
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
void InternalLoader::openPlatformConsole() {
|
|
|
|
m_platformConsoleOpen = true;
|
|
|
|
|
2022-11-30 11:51:38 -05:00
|
|
|
for (auto const& log : log::Logs::list()) {
|
2022-11-22 10:21:00 -05:00
|
|
|
std::cout << log->toString(true) << "\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void InternalLoader::closePlatformConsole() {
|
|
|
|
m_platformConsoleOpen = false;
|
|
|
|
}
|
|
|
|
|
2022-11-30 11:51:38 -05:00
|
|
|
CFDataRef msgPortCallback(
|
|
|
|
CFMessagePortRef port,
|
|
|
|
SInt32 messageID,
|
|
|
|
CFDataRef data,
|
|
|
|
void* info
|
|
|
|
) {
|
|
|
|
if(!CFDataGetLength(data))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
std::string cdata(
|
|
|
|
reinterpret_cast<char const*>(CFDataGetBytePtr(data)),
|
|
|
|
CFDataGetLength(data)
|
|
|
|
);
|
|
|
|
|
|
|
|
std::string reply = InternalLoader::processRawIPC(port, cdata);
|
|
|
|
return CFDataCreate(NULL, (const UInt8*)reply.data(), reply.size());
|
|
|
|
}
|
2022-11-22 10:21:00 -05:00
|
|
|
|
|
|
|
void InternalLoader::setupIPC() {
|
2022-11-30 11:51:38 -05:00
|
|
|
std::thread([]() {
|
|
|
|
CFStringRef portName = CFStringCreateWithCString(NULL, IPC_PORT_NAME, kCFStringEncodingUTF8);
|
|
|
|
|
|
|
|
CFMessagePortRef localPort = CFMessagePortCreateLocal(
|
|
|
|
NULL,
|
|
|
|
portName,
|
|
|
|
msgPortCallback,
|
|
|
|
NULL,
|
|
|
|
NULL
|
|
|
|
);
|
|
|
|
CFRunLoopSourceRef runLoopSource = CFMessagePortCreateRunLoopSource(NULL, localPort, 0);
|
|
|
|
|
|
|
|
CFRunLoopAddSource(
|
|
|
|
CFRunLoopGetCurrent(),
|
|
|
|
runLoopSource,
|
|
|
|
kCFRunLoopCommonModes
|
|
|
|
);
|
|
|
|
CFRunLoopRun();
|
|
|
|
CFRelease(localPort);
|
|
|
|
}).detach();
|
2022-11-22 10:21:00 -05:00
|
|
|
log::log(Severity::Warning, InternalMod::get(), "IPC is not supported on this platform");
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|