implement missing stuff to macos

This commit is contained in:
altalk23 2023-08-11 17:35:25 +03:00 committed by ConfiG
parent a9cce769d5
commit 0e1d639002
No known key found for this signature in database
GPG key ID: 44DA1983F524C11B
4 changed files with 33 additions and 9 deletions

View file

@ -1,3 +1,5 @@
#pragma once
#include "FileWatcher.hpp"
#include <json.hpp>

View file

@ -5,6 +5,7 @@ using namespace geode::prelude;
#if defined(GEODE_IS_MACOS)
#include "mac/LoaderImpl.mm"
#include "mac/main.mm"
#include "mac/crashlog.mm"
#include "mac/FileWatcher.mm"

View file

@ -3,10 +3,7 @@
#include <iostream>
#include <loader/LoaderImpl.hpp>
#include <loader/ModImpl.hpp>
#ifdef GEODE_IS_MACOS
#include <CoreFoundation/CoreFoundation.h>
#import <Foundation/Foundation.h>
using namespace geode::prelude;
@ -36,6 +33,9 @@ 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
m_platformConsoleOpen = true;
for (auto const& log : log::Logger::list()) {
@ -83,5 +83,3 @@ void Loader::Impl::setupIPC() {
bool Loader::Impl::userTriedToLoadDLLs() const {
return false;
}
#endif

View file

@ -181,7 +181,7 @@ ghc::filesystem::path dirs::getGameDir() {
_NSGetExecutablePath(gddir.data(), &out);
ghc::filesystem::path gdpath = gddir.data();
auto currentPath = gdpath.parent_path().parent_path();
auto currentPath = ghc::filesystem::canonical(gdpath.parent_path().parent_path());
return currentPath;
}();
@ -208,8 +208,31 @@ void geode::utils::game::restart() {
return;
}
// TODO: implement restarting on mac
log::warn("Restarting is not yet implemented on macOS!");
auto restart = +[] {
log::info("Restarting game...");
auto gdExec = dirs::getGameDir() / "MacOS" / "Geometry Dash";
NSTask *task = [NSTask new];
[task setLaunchPath: [NSString stringWithUTF8String: gdExec.string().c_str()]];
[task launch];
};
class Exit : public CCObject {
public:
void shutdown() {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wobjc-method-access"
[[[NSClassFromString(@"AppControllerManager") sharedInstance] controller] shutdownGame];
#pragma clang diagnostic pop
}
};
std::atexit(restart);
CCDirector::get()->getActionManager()->addAction(CCSequence::create(
CCDelayTime::create(0.5f),
CCCallFunc::create(nullptr, callfunc_selector(Exit::shutdown)),
nullptr
), CCDirector::get()->getRunningScene(), false);
}
#endif