make safeModeCheck return a boolean

This commit is contained in:
mat 2024-06-24 21:25:55 -03:00 committed by GitHub
parent e4905a0a20
commit c2e9eb9718
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 30 additions and 22 deletions

View file

@ -84,21 +84,26 @@ 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();
}
}
bool 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
);
return choice == IDYES;
}
return false;
}
#else !defined(GEODE_IS_MACOS)
// macos is defined in load.mm, this is for android
// on android the launcher just adds the launch args to enable safe mode
bool safeModeCheck() {
return false;
}
#endif
int geodeEntry(void* platformData) {
@ -110,7 +115,9 @@ int geodeEntry(void* platformData) {
console::openIfClosed();
}
safeModeCheck();
if (safeModeCheck()) {
LoaderImpl::get()->forceSafeMode();
}
std::string forwardCompatSuffix;
if (LoaderImpl::get()->isForwardCompatMode())

View file

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

View file

@ -1,14 +1,15 @@
#include "load.hpp"
#include <loader/LoaderImpl.hpp>
#include <loader/LogImpl.hpp>
#include <Geode/platform/cplatform.h>
#ifdef GEODE_IS_MACOS
#include <loader/LoaderImpl.hpp>
#include <loader/LogImpl.hpp>
#include <CoreGraphics/CoreGraphics.h>
#include <AppKit/AppKit.h>
#include <Cocoa/Cocoa.h>
void safeModeCheck() {
bool 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?";
@ -16,10 +17,10 @@ void safeModeCheck() {
NSButton *cancelButton = [alert addButtonWithTitle:@"No"];
alert.window.defaultButtonCell = cancelButton.cell;
NSModalResponse choice = [alert runModal];
if (choice == NSAlertFirstButtonReturn) { // if Yes is clicked
LoaderImpl::get()->forceSafeMode();
}
// if Yes is clicked
return choice == NSAlertFirstButtonReturn;
}
return false;
}
#endif