diff --git a/nx/include/switch/services/applet.h b/nx/include/switch/services/applet.h index e8bb425a..165d8c10 100644 --- a/nx/include/switch/services/applet.h +++ b/nx/include/switch/services/applet.h @@ -946,6 +946,18 @@ Result appletCreateLibraryApplet(AppletHolder *h, AppletId id, LibAppletMode mod */ Result appletCreateLibraryAppletSelf(AppletHolder *h, AppletId id, LibAppletMode mode); +/** + * @brief TerminateAllLibraryApplets which were created by the current applet. + * @note Normally LibraryApplet cleanup should be handled via \ref AppletHolder. + */ +Result appletTerminateAllLibraryApplets(void); + +/** + * @brief AreAnyLibraryAppletsLeft which were created by the current applet. + * @param[out] out Output flag. + */ +Result appletAreAnyLibraryAppletsLeft(bool *out); + /// Closes an AppletHolder object. void appletHolderClose(AppletHolder *h); @@ -1548,6 +1560,17 @@ AppletApplicationExitReason appletApplicationGetExitReason(AppletApplication *a) */ Result appletApplicationRequestForApplicationToGetForeground(AppletApplication *a); +/** + * @brief TerminateAllLibraryApplets which were created by the Application. + */ +Result appletApplicationTerminateAllLibraryApplets(AppletApplication *a); + +/** + * @brief AreAnyLibraryAppletsLeft which were created by the Application. + * @param[out] out Output flag. + */ +Result appletApplicationAreAnyLibraryAppletsLeft(AppletApplication *a, bool *out); + /** * @brief Calls the same func as \ref appletHolderRequestExitOrTerminate with the output IAppletAccessor from the GetCurrentLibraryApplet cmd. * @param a \ref AppletApplication diff --git a/nx/source/services/applet.c b/nx/source/services/applet.c index 75701eb1..4b35606a 100644 --- a/nx/source/services/applet.c +++ b/nx/source/services/applet.c @@ -2924,6 +2924,14 @@ Result appletCreateLibraryAppletSelf(AppletHolder *h, AppletId id, LibAppletMode return _appletHolderCreate(h, id, mode, true); } +Result appletTerminateAllLibraryApplets(void) { + return _appletCmdNoIO(&g_appletILibraryAppletCreator, 1); +} + +Result appletAreAnyLibraryAppletsLeft(bool *out) { + return _appletCmdNoInOutBool(&g_appletILibraryAppletCreator, out, 2); +} + void appletHolderClose(AppletHolder *h) { eventClose(&h->PopInteractiveOutDataEvent); @@ -4569,6 +4577,20 @@ Result appletApplicationRequestForApplicationToGetForeground(AppletApplication * return rc; } +Result appletApplicationTerminateAllLibraryApplets(AppletApplication *a) { + if (!serviceIsActive(&a->s)) + return MAKERESULT(Module_Libnx, LibnxError_NotInitialized); + + return _appletCmdNoIO(&a->s, 110); +} + +Result appletApplicationAreAnyLibraryAppletsLeft(AppletApplication *a, bool *out) { + if (!serviceIsActive(&a->s)) + return MAKERESULT(Module_Libnx, LibnxError_NotInitialized); + + return _appletCmdNoInOutBool(&a->s, out, 111); +} + Result appletApplicationRequestExitLibraryAppletOrTerminate(AppletApplication *a, u64 timeout) { Result rc=0; Service srv={0};