From 1c948e2d32d6af888a046ef16daefa4e13dee0a6 Mon Sep 17 00:00:00 2001 From: leo60228 Date: Tue, 18 Sep 2018 16:07:58 -0400 Subject: [PATCH] applet: Add appletSelfExit() --- nx/include/switch/services/applet.h | 6 ++++++ nx/source/services/applet.c | 31 +++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/nx/include/switch/services/applet.h b/nx/include/switch/services/applet.h index 0fb52e1c..91405077 100644 --- a/nx/include/switch/services/applet.h +++ b/nx/include/switch/services/applet.h @@ -71,6 +71,12 @@ Result appletSetScreenShotPermission(s32 val); Result appletSetScreenShotImageOrientation(s32 val); +/** + * @brief Exits the application. + * @note Can only be used with AppletType_Application. + */ +Result appletSelfExit(void); + /** * @brief Processes the current applet status. Generally used within a main loop. * @return Whether the application should continue running. diff --git a/nx/source/services/applet.c b/nx/source/services/applet.c index ec1f6747..01280a92 100644 --- a/nx/source/services/applet.c +++ b/nx/source/services/applet.c @@ -1071,6 +1071,37 @@ Result appletSetScreenShotImageOrientation(s32 val) { return rc; } +Result appletSelfExit(void) { + IpcCommand c; + ipcInitialize(&c); + + struct { + u64 magic; + u64 cmd_id; + } *raw; + + raw = ipcPrepareHeader(&c, sizeof(*raw)); + + raw->magic = SFCI_MAGIC; + raw->cmd_id = 0; + + Result rc = serviceIpcDispatch(&g_appletISelfController); + + if (R_SUCCEEDED(rc)) { + IpcParsedCommand r; + ipcParse(&r); + + struct { + u64 magic; + u64 result; + } *resp = r.Raw; + + rc = resp->result; + } + + return rc; +} + Result appletCreateManagedDisplayLayer(u64 *out) { IpcCommand c; ipcInitialize(&c);