Implement the RESTART_APP system request for Mac

This commit is contained in:
Henrik Rydgård 2023-04-29 11:17:10 +02:00
parent 2507fcb89b
commit c81d996475
4 changed files with 26 additions and 8 deletions

View File

@ -75,7 +75,8 @@ SDLJoystick *joystick = NULL;
GlobalUIState lastUIState = UISTATE_MENU;
GlobalUIState GetUIState();
static int g_QuitRequested = 0;
static bool g_QuitRequested = false;
static bool g_RestartRequested = false;
static int g_DesktopWidth = 0;
static int g_DesktopHeight = 0;
@ -189,8 +190,10 @@ void System_Vibrate(int length_ms) {
bool System_MakeRequest(SystemRequestType type, int requestId, const std::string &param1, const std::string &param2, int param3) {
switch (type) {
case SystemRequestType::RESTART_APP:
g_RestartRequested = true;
return true;
case SystemRequestType::EXIT_APP:
case SystemRequestType::RESTART_APP: // Not sure how we best do this, but do a clean exit, better than being stuck in a bad state.
// Do a clean exit
g_QuitRequested = true;
return true;
@ -1277,14 +1280,15 @@ int main(int argc, char *argv[]) {
break;
}
}
if (g_QuitRequested)
if (g_QuitRequested || g_RestartRequested)
break;
const uint8_t *keys = SDL_GetKeyboardState(NULL);
if (emuThreadState == (int)EmuThreadState::DISABLED) {
UpdateRunLoop();
}
if (g_QuitRequested)
if (g_QuitRequested || g_RestartRequested)
break;
#if !defined(MOBILE_DEVICE)
if (lastUIState != GetUIState()) {
lastUIState = GetUIState();
@ -1334,10 +1338,8 @@ int main(int argc, char *argv[]) {
break;
}
graphicsContext->SwapBuffers();
{
std::lock_guard<std::mutex> guard(g_mutexWindow);
if (g_windowState.update) {
@ -1393,5 +1395,12 @@ int main(int argc, char *argv[]) {
#ifdef HAVE_LIBNX
socketExit();
#endif
// If a restart was requested (and supported on this platform), respawn the executable.
if (g_RestartRequested) {
#if PPSSPP_PLATFORM(MAC)
RestartMacApp();
#endif
}
return 0;
}

View File

@ -351,8 +351,6 @@ static void CustomApplicationMain (int argc, char **argv)
@end
#ifdef main
# undef main
#endif

View File

@ -33,3 +33,4 @@ private:
#endif // PPSSPP_PLATFORM(IOS)
};
void RestartMacApp();

View File

@ -115,3 +115,13 @@ void DarwinFileSystemServices::setUserPreferredMemoryStickDirectory(Path path) {
g_Config.memStickDirectory = path;
}
void RestartMacApp() {
#if PPSSPP_PLATFORM(MAC)
NSURL *bundleURL = NSBundle.mainBundle.bundleURL;
NSTask *task = [[NSTask alloc] init];
task.executableURL = [NSURL fileURLWithPath:@"/usr/bin/open"];
task.arguments = @[@"-n", bundleURL.path];
[task launch];
exit(0);
#endif
}