mirror of
https://github.com/geode-sdk/geode.git
synced 2025-03-25 04:11:42 -04:00
proper platform console for mac
This commit is contained in:
parent
6d599a5e19
commit
3f8cdd994a
3 changed files with 57 additions and 4 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -31,6 +31,7 @@
|
|||
**/*.tmlanguage.cache
|
||||
**/*.tmPreferences.cache
|
||||
**/*.stTheme.cache
|
||||
.cache
|
||||
|
||||
# Workspace files are user-specific
|
||||
**/*.sublime-workspace
|
||||
|
|
|
@ -72,10 +72,12 @@ namespace geode {
|
|||
|
||||
std::vector<utils::MiniFunction<void(void)>> m_gdThreadQueue;
|
||||
mutable std::mutex m_gdThreadMutex;
|
||||
bool m_platformConsoleOpen = false;
|
||||
std::vector<std::pair<Hook*, Mod*>> m_internalHooks;
|
||||
bool m_readyToHook = false;
|
||||
|
||||
bool m_platformConsoleOpen = false;
|
||||
void* m_platformData = nullptr;
|
||||
|
||||
std::mutex m_nextModMutex;
|
||||
std::unique_lock<std::mutex> m_nextModLock = std::unique_lock<std::mutex>(m_nextModMutex, std::defer_lock);
|
||||
std::condition_variable m_nextModCV;
|
||||
|
|
|
@ -4,9 +4,16 @@
|
|||
#include <loader/LoaderImpl.hpp>
|
||||
#include <loader/ModImpl.hpp>
|
||||
#import <Foundation/Foundation.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
using namespace geode::prelude;
|
||||
|
||||
struct MacConsoleData {
|
||||
std::string logFile;
|
||||
std::string scriptFile;
|
||||
int logFd;
|
||||
};
|
||||
|
||||
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);
|
||||
|
@ -33,9 +40,42 @@ void Loader::Impl::logConsoleMessageWithSeverity(std::string const& msg, Severit
|
|||
}
|
||||
|
||||
void Loader::Impl::openPlatformConsole() {
|
||||
// it's not possible to redirect stdout to a terminal
|
||||
// and the console.app is too clunky
|
||||
|
||||
if (m_platformConsoleOpen) return;
|
||||
|
||||
std::string outFile = "/tmp/command_output_XXXXXX";
|
||||
int outFd = mkstemp(&outFile[0]);
|
||||
|
||||
auto script = outFile + ".command";
|
||||
auto scriptContent = fmt::format(R"(
|
||||
#!/bin/sh
|
||||
echo -n -e "\033]0;Geode Console\007"
|
||||
tail -f {} &
|
||||
trap "" SIGINT
|
||||
while [ $(lsof -t {} 2>/dev/null | wc -l) -gt 1 ]; do :; done
|
||||
osascript -e 'tell application "Terminal"
|
||||
close (every window whose name contains "Geode Console")
|
||||
if (count windows) is 0 then quit
|
||||
end tell' &
|
||||
exit
|
||||
)", outFile, outFile);
|
||||
|
||||
if (file::writeString(script, scriptContent)) {
|
||||
chmod(script.c_str(), 0777);
|
||||
dup2(outFd, 1);
|
||||
dup2(outFd, 2);
|
||||
|
||||
NSTask *task = [[NSTask alloc] init];
|
||||
task.launchPath = @"/usr/bin/open";
|
||||
task.arguments = @[[NSString stringWithUTF8String:script.c_str()]];
|
||||
[task launch];
|
||||
|
||||
m_platformData = new MacConsoleData {
|
||||
outFile,
|
||||
script,
|
||||
outFd
|
||||
};
|
||||
}
|
||||
|
||||
m_platformConsoleOpen = true;
|
||||
|
||||
for (auto const& log : log::Logger::list()) {
|
||||
|
@ -44,6 +84,16 @@ void Loader::Impl::openPlatformConsole() {
|
|||
}
|
||||
|
||||
void Loader::Impl::closePlatformConsole() {
|
||||
if (m_platformData) {
|
||||
auto consoleData = reinterpret_cast<MacConsoleData*>(m_platformData);
|
||||
close(consoleData->logFd);
|
||||
unlink(consoleData->logFile.c_str());
|
||||
unlink(consoleData->scriptFile.c_str());
|
||||
|
||||
delete consoleData;
|
||||
m_platformData = nullptr;
|
||||
}
|
||||
|
||||
m_platformConsoleOpen = false;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue