geode/loader/src/platform/mac/LoaderImpl.cpp

72 lines
2.2 KiB
C++
Raw Normal View History

2022-12-04 11:39:40 -05:00
#include <Geode/loader/IPC.hpp>
#include <Geode/loader/Log.hpp>
2022-12-04 11:39:40 -05:00
#include <iostream>
#include <loader/LoaderImpl.hpp>
#include <loader/ModImpl.hpp>
#ifdef GEODE_IS_MACOS
2022-12-04 11:39:40 -05:00
#include <CoreFoundation/CoreFoundation.h>
2022-12-14 06:11:19 -05:00
USE_GEODE_NAMESPACE();
2022-12-10 11:30:14 -05:00
void Loader::Impl::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
);
}
2022-12-10 11:30:14 -05:00
void Loader::Impl::openPlatformConsole() {
m_platformConsoleOpen = true;
2022-12-12 14:32:44 -05:00
for (auto const& log : log::Logger::list()) {
std::cout << log->toString(true) << "\n";
}
}
2022-12-10 11:30:14 -05:00
void Loader::Impl::closePlatformConsole() {
m_platformConsoleOpen = false;
}
2022-12-04 11:39:40 -05:00
CFDataRef msgPortCallback(CFMessagePortRef port, SInt32 messageID, CFDataRef data, void* info) {
if (!CFDataGetLength(data)) return NULL;
2022-11-30 11:51:38 -05:00
2022-12-04 11:39:40 -05:00
std::string cdata(reinterpret_cast<char const*>(CFDataGetBytePtr(data)), CFDataGetLength(data));
2022-11-30 11:51:38 -05:00
std::string reply = LoaderImpl::get()->processRawIPC(port, cdata);
2022-12-04 11:39:40 -05:00
return CFDataCreate(NULL, (UInt8 const*)reply.data(), reply.size());
2022-11-30 11:51:38 -05:00
}
2022-12-10 11:30:14 -05:00
void Loader::Impl::setupIPC() {
2022-11-30 11:51:38 -05:00
std::thread([]() {
CFStringRef portName = CFStringCreateWithCString(NULL, IPC_PORT_NAME, kCFStringEncodingUTF8);
2022-12-04 11:39:40 -05:00
CFMessagePortRef localPort =
CFMessagePortCreateLocal(NULL, portName, msgPortCallback, NULL, NULL);
if (localPort == NULL) {
log::warn("Unable to create port, quitting IPC");
return;
}
2022-11-30 11:51:38 -05:00
CFRunLoopSourceRef runLoopSource = CFMessagePortCreateRunLoopSource(NULL, localPort, 0);
2022-12-04 11:39:40 -05:00
if (runLoopSource == NULL) {
log::warn("Unable to create loop source, quitting IPC");
return;
}
CFRunLoopAddSource(CFRunLoopGetCurrent(), runLoopSource, kCFRunLoopCommonModes);
2022-11-30 11:51:38 -05:00
CFRunLoopRun();
CFRelease(localPort);
}).detach();
2022-12-04 11:39:40 -05:00
log::debug("IPC set up");
}
bool Loader::Impl::userTriedToLoadDLLs() const {
2023-01-24 03:45:18 -05:00
return false;
}
#endif