From c60bdb3670b2eab0c3459d9f48f57e432726af4c Mon Sep 17 00:00:00 2001 From: yellows8 Date: Tue, 18 Nov 2014 23:48:50 -0500 Subject: [PATCH] With RUNFLAG_APTWORKAROUND enabled, at the start of aptReturnToMenu just set the status to APP_EXITING then return(this func won't actually get executed with RUNFLAG_APTWORKAROUND atm). Updated __handle_notification() to check for errors from APT_InquireNotification. In aptExit only call the applet-utility code when RUNFLAG_APTWORKAROUND is not set. Minor other changes. Fixed APT_CheckNew3DS code so that it properly only uses one of the APT cmds. --- libctru/source/services/apt.c | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/libctru/source/services/apt.c b/libctru/source/services/apt.c index db3b011..4f417fa 100644 --- a/libctru/source/services/apt.c +++ b/libctru/source/services/apt.c @@ -145,6 +145,13 @@ void aptReturnToMenu() u32 ns_capinfo[0x20>>2]; u32 tmp_params[0x20>>2]; + if(__system_runflags&RUNFLAG_APTWORKAROUND) + { + svcClearEvent(aptStatusEvent); + aptSetStatus(APP_EXITING); + return; + } + // This is only executed when ret-to-menu was triggered via the home-button, not the power-button. if(aptGetStatusPower() == 0) { @@ -209,12 +216,15 @@ void aptReturnToMenu() static void __handle_notification() { u8 type; + Result ret=0; // Get notification type. aptOpenSession(); - APT_InquireNotification(NULL, currentAppId, &type); + ret = APT_InquireNotification(NULL, currentAppId, &type); aptCloseSession(); + if(ret!=0)return; + switch(type) { case APTSIGNAL_HOMEBUTTON: @@ -367,7 +377,7 @@ Result aptInit(void) void aptExit() { - aptAppletUtility_Exit_RetToApp(); + if(!(__system_runflags&RUNFLAG_APTWORKAROUND))aptAppletUtility_Exit_RetToApp(); // This is only executed when application-termination was triggered via the home-menu power-off screen. if(aptGetStatusPower() == 1) @@ -399,6 +409,8 @@ bool aptMainLoop() { while(1) { + //if(__system_runflags&RUNFLAG_APTWORKAROUND)__handle_notification(); + switch(aptGetStatus()) { case APP_RUNNING: @@ -461,11 +473,8 @@ APP_STATUS aptGetStatus() void aptSetStatus(APP_STATUS status) { - u32 prevstatus; - svcWaitSynchronization(aptStatusMutex, U64_MAX); - prevstatus = aptStatus; aptStatus = status; //if(prevstatus != APP_NOTINITIALIZED) @@ -876,8 +885,14 @@ Result APT_CheckNew3DS(Handle* handle, u8 *out) } aptOpenSession(); - if(currentAppId==APPID_APPLICATION)ret = APT_CheckNew3DS_Application(NULL, out); - ret = APT_CheckNew3DS_System(NULL, out); + if(currentAppId==APPID_APPLICATION) + { + ret = APT_CheckNew3DS_Application(NULL, out); + } + else + { + ret = APT_CheckNew3DS_System(NULL, out); + } aptCloseSession(); __apt_new3dsflag_initialized = 1;