diff --git a/libctru/include/3ds/services/apt.h b/libctru/include/3ds/services/apt.h index d73dd16..ae961e8 100644 --- a/libctru/include/3ds/services/apt.h +++ b/libctru/include/3ds/services/apt.h @@ -135,6 +135,18 @@ void aptWaitStatusEvent(void); /// Signals that the app is ready to sleep. void aptSignalReadyForSleep(void); +/** + * @brief Gets whether to allow the system to enter sleep mode. + * @return Whether sleep mode is allowed. + */ +bool aptIsSleepAllowed(); + +/** + * @brief Sets whether to allow the system to enter sleep mode. + * @param allowed Whether to allow sleep mode. + */ +void aptSetSleepAllowed(bool allowed); + /** * @brief Gets the menu's app ID. * @return The menu's app ID. diff --git a/libctru/source/services/apt.c b/libctru/source/services/apt.c index d3554ce..688c16e 100644 --- a/libctru/source/services/apt.c +++ b/libctru/source/services/apt.c @@ -37,6 +37,7 @@ APT_AppStatus aptStatus = APP_NOTINITIALIZED; APT_AppStatus aptStatusBeforeSleep = APP_NOTINITIALIZED; u32 aptStatusPower; Handle aptSleepSync; +static bool aptSleepAllowed = true; u32 aptParameters[0x1000/4]; //TEMP @@ -336,14 +337,22 @@ static void __handle_notification(void) { case APTSIGNAL_PREPARESLEEP: // Reply to sleep-request. - aptStatusBeforeSleep = aptGetStatus(); - aptSetStatus(APP_PREPARE_SLEEPMODE); - svcWaitSynchronization(aptSleepSync, U64_MAX); - svcClearEvent(aptSleepSync); + if(aptIsSleepAllowed()) + { + aptStatusBeforeSleep = aptGetStatus(); + aptSetStatus(APP_PREPARE_SLEEPMODE); + svcWaitSynchronization(aptSleepSync, U64_MAX); + svcClearEvent(aptSleepSync); - aptOpenSession(); - APT_ReplySleepQuery(currentAppId, 0x1); - aptCloseSession(); + aptOpenSession(); + APT_ReplySleepQuery(currentAppId, 0x1); + aptCloseSession(); + } else + { + aptOpenSession(); + APT_ReplySleepQuery(currentAppId, 0x0); + aptCloseSession(); + } break; case APTSIGNAL_ENTERSLEEP: @@ -710,6 +719,16 @@ void aptSignalReadyForSleep(void) svcSignalEvent(aptSleepSync); } +bool aptIsSleepAllowed() +{ + return aptSleepAllowed; +} + +void aptSetSleepAllowed(bool allowed) +{ + aptSleepAllowed = allowed; +} + Result APT_GetLockHandle(u16 flags, Handle* lockHandle) { u32* cmdbuf=getThreadCommandBuffer();