Add Safe Mode for MacOS

This commit is contained in:
shloakmenon 2024-06-24 20:18:41 -04:00
parent 08d8af3f61
commit e4905a0a20
4 changed files with 47 additions and 15 deletions

View file

@ -89,6 +89,7 @@ file(GLOB SOURCES CONFIGURE_DEPENDS
# Obj-c sources
file(GLOB OBJC_SOURCES
src/platform/Objcpp.mm
src/load.mm
)
set_source_files_properties(${OBJC_SOURCES} PROPERTIES SKIP_PRECOMPILE_HEADERS ON)

View file

@ -83,6 +83,24 @@ void tryShowForwardCompat() {
);
}
#ifdef GEODE_IS_WINDOWS
void safeModeCheck() {
// yes this is quite funny
if (GetAsyncKeyState(VK_SHIFT) != 0) {
auto choice = MessageBoxA(
NULL,
"(This has been triggered because you were holding SHIFT)\n"
"Do you want to activate Geode Safe Mode? This disables loading any mods.",
"Attention",
MB_YESNO | MB_ICONINFORMATION
);
if (choice == IDYES) {
LoaderImpl::get()->forceSafeMode();
}
}
}
#endif
int geodeEntry(void* platformData) {
thread::setName("Main");
@ -91,21 +109,8 @@ int geodeEntry(void* platformData) {
if (LoaderImpl::get()->isForwardCompatMode()) {
console::openIfClosed();
}
#ifdef GEODE_IS_WINDOWS
// yes this is quite funny
if (GetAsyncKeyState(VK_SHIFT) != 0) {
auto choice = MessageBoxA(
NULL,
"(This has been triggered because you were holding SHIFT)\n"
"Do you want to activate Geode Safe Mode? This disables loading any mods.",
"Attention",
MB_YESNO | MB_ICONINFORMATION
);
if (choice == IDYES) {
LoaderImpl::get()->forceSafeMode();
}
}
#endif
safeModeCheck();
std::string forwardCompatSuffix;
if (LoaderImpl::get()->isForwardCompatMode())

View file

@ -1,2 +1,3 @@
#pragma once
void safeModeCheck();
int geodeEntry(void* platformData);

25
loader/src/load.mm Normal file
View file

@ -0,0 +1,25 @@
#include "load.hpp"
#include <loader/LoaderImpl.hpp>
#include <loader/LogImpl.hpp>
#ifdef GEODE_IS_MACOS
#include <CoreGraphics/CoreGraphics.h>
#include <AppKit/AppKit.h>
#include <Cocoa/Cocoa.h>
void safeModeCheck() {
if (CGEventSourceKeyState(kCGEventSourceStateHIDSystemState, (CGKeyCode)56)) { // 56 is Shift key
NSAlert *alert = [NSAlert new];
alert.messageText = @"The shift key was held down. Would you like to enable safe mode?";
[alert addButtonWithTitle:@"Yes"];
NSButton *cancelButton = [alert addButtonWithTitle:@"No"];
alert.window.defaultButtonCell = cancelButton.cell;
NSModalResponse choice = [alert runModal];
if (choice == NSAlertFirstButtonReturn) { // if Yes is clicked
LoaderImpl::get()->forceSafeMode();
}
}
}
#endif