From 1fccd4a1bb150301fed8a47987f4e62fcf376902 Mon Sep 17 00:00:00 2001 From: yellows8 Date: Sun, 24 Dec 2017 23:31:58 -0500 Subject: [PATCH] Improved handling for appletNotifyRunning(). --- nx/include/switch/services/applet.h | 1 + nx/source/services/applet.c | 13 +++++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/nx/include/switch/services/applet.h b/nx/include/switch/services/applet.h index 281d2160..12fc585b 100644 --- a/nx/include/switch/services/applet.h +++ b/nx/include/switch/services/applet.h @@ -39,6 +39,7 @@ Result appletInitialize(void); void appletExit(void); Result appletGetAppletResourceUserId(u64 *out); +void appletNotifyRunning(u8 *out); Result appletCreateManagedDisplayLayer(u64 *out); /** diff --git a/nx/source/services/applet.c b/nx/source/services/applet.c index b57d1f19..4bb40140 100644 --- a/nx/source/services/applet.c +++ b/nx/source/services/applet.c @@ -26,6 +26,8 @@ static u8 g_appletOperationMode; static u32 g_appletPerformanceMode; static u8 g_appletFocusState; +static bool g_appletNotifiedRunning = 0; + static appletHookCookie appletFirstHook; void appletExit(void); @@ -34,7 +36,6 @@ static Result _appletGetSession(Handle sessionhandle, Handle* handle_out, u64 cm static Result _appletGetSessionProxy(Handle sessionhandle, Handle* handle_out, u64 cmd_id, Handle prochandle, u8 *AppletAttribute); static Result _appletGetAppletResourceUserId(u64 *out); -static Result _appletNotifyRunning(u8 *out); static Result appletSetFocusHandlingMode(u32 mode); @@ -61,6 +62,7 @@ Result appletInitialize(void) { if (__nx_applet_type==APPLET_TYPE_None) return 0; g_appletResourceUserId = 0; + g_appletNotifiedRunning = 0; if (__nx_applet_type==APPLET_TYPE_Default) __nx_applet_type = APPLET_TYPE_Application; @@ -141,7 +143,7 @@ Result appletInitialize(void) { if (R_SUCCEEDED(rc)) rc = appletSetFocusHandlingMode(0); } - if (R_SUCCEEDED(rc) && __nx_applet_auto_notifyrunning && __nx_applet_type==APPLET_TYPE_Application) rc = _appletNotifyRunning(NULL); + if (R_SUCCEEDED(rc) && __nx_applet_auto_notifyrunning) appletNotifyRunning(NULL); if (R_SUCCEEDED(rc)) rc = _appletGetOperationMode(&g_appletOperationMode); if (R_SUCCEEDED(rc)) rc = _appletGetPerformanceMode(&g_appletPerformanceMode); @@ -439,10 +441,13 @@ Result appletGetAppletResourceUserId(u64 *out) { return 0; } -static Result _appletNotifyRunning(u8 *out) { +void appletNotifyRunning(u8 *out) { IpcCommand c; ipcInitialize(&c); + if (__nx_applet_type!=APPLET_TYPE_Application || g_appletNotifiedRunning) return; + g_appletNotifiedRunning = 1; + struct { u64 magic; u64 cmd_id; @@ -472,7 +477,7 @@ static Result _appletNotifyRunning(u8 *out) { } } - return rc; + if (R_FAILED(rc)) fatalSimple(rc); } static Result _appletReceiveMessage(u32 *out) {