whb: Fix proc to better support HBL launched applications.

Should exit cleanly to HBL now.

TODO: Is it possible to auto detect if we were launched from HBL?
This commit is contained in:
James Benton 2017-06-02 11:48:59 +01:00
parent 79345f239f
commit 2c18b246ae
2 changed files with 57 additions and 6 deletions

View File

@ -1,8 +1,18 @@
#pragma once
#include <wut.h>
/**
* \defgroup whb_proc ProcUI Utilities
* \ingroup whb
* @{
*/
#ifdef __cplusplus
extern "C" {
#endif
void
WHBProcInit();
WHBProcInit(BOOL fromHBL);
void
WHBProcShutdown();
@ -12,3 +22,9 @@ WHBProcStopRunning();
BOOL
WHBProcIsRunning();
#ifdef __cplusplus
}
#endif
/** @} */

View File

@ -1,8 +1,13 @@
#include <whb/proc.h>
#include <coreinit/core.h>
#include <coreinit/exit.h>
#include <coreinit/foreground.h>
#include <coreinit/systeminfo.h>
#include <coreinit/messagequeue.h>
#include <gx2/event.h>
#include <proc_ui/procui.h>
#include <sysapp/launch.h>
#include <whb/log.h>
#include <whb/proc.h>
static uint32_t
sMainCore;
@ -10,28 +15,59 @@ sMainCore;
static BOOL
sRunning = FALSE;
static BOOL
sFromHBL = FALSE;
static ProcUICallback
sAcquireCallback = NULL;
static uint32_t
ProcSaveCallback(void *context)
procSaveCallback(void *context)
{
OSSavesDone_ReadyToRelease();
return 0;
}
static uint32_t
procHomeButtonDenied(void *context)
{
if (sFromHBL) {
WHBProcStopRunning();
}
return 0;
}
void
WHBProcInit()
WHBProcInit(BOOL fromHBL)
{
sMainCore = OSGetCoreId();
sRunning = TRUE;
ProcUIInitEx(&ProcSaveCallback, NULL);
// Homebrew Launcher does not like the standard ProcUI application loop,
// so instead we disable the home buttom menu and use the home button
// to trigger an exit.
sFromHBL = fromHBL;
if (sFromHBL) {
// Important: OSEnableHomeButtonMenu must come before ProcUIInitEx.
OSEnableHomeButtonMenu(FALSE);
}
ProcUIInitEx(&procSaveCallback, NULL);
ProcUIRegisterCallback(PROCUI_CALLBACK_HOME_BUTTON_DENIED, &procHomeButtonDenied, NULL, 100);
}
void
WHBProcShutdown()
{
sRunning = FALSE;
// If we're running from Homebrew Launcher we must do a SYSRelaunchTitle to
// correctly return to HBL.
if (sFromHBL) {
SYSRelaunchTitle(0, NULL);
}
}
void
@ -58,7 +94,6 @@ WHBProcIsRunning()
}
if (!sRunning) {
GX2DrawDone();
ProcUIShutdown();
}