From c95cd26d5c19e061c2fb548b3f18394be7d8a189 Mon Sep 17 00:00:00 2001 From: Lena Date: Sat, 17 Feb 2024 01:55:04 +0100 Subject: [PATCH 1/9] add low hanging sleep/homemenu apt functions --- ctru-rs/src/services/apt.rs | 48 +++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/ctru-rs/src/services/apt.rs b/ctru-rs/src/services/apt.rs index 89ad255..ef09527 100644 --- a/ctru-rs/src/services/apt.rs +++ b/ctru-rs/src/services/apt.rs @@ -82,6 +82,54 @@ impl Apt { Ok(()) } } + + /// Set if the console is allowed to enter sleep mode. + /// + /// You can check whether the console is allowed to sleep with [Apt::is_sleep_allowed]. + #[doc(alias = "aptSetSleepAllowed")] + pub fn set_sleep_allowed(&mut self, allowed: bool) { + unsafe { + ctru_sys::aptSetSleepAllowed(allowed); + } + } + + /// Check if the console is allowed to enter sleep mode. + /// + /// You can set whether the console is allowed to sleep with [Apt::set_sleep_allowed]. + #[doc(alias = "aptIsSleepAllowed")] + pub fn is_sleep_allowed(&mut self) -> bool { + unsafe { + ctru_sys::aptIsSleepAllowed() + } + } + + /// Set if the console is allowed to enter the home menu. + /// + /// You can check whether the console is allowed to enter the home menu with [Apt::is_home_allowed]. + #[doc(alias = "aptSetHomeAllowed")] + pub fn set_home_allowed(&mut self, allowed: bool) { + unsafe { + ctru_sys::aptSetHomeAllowed(allowed); + } + } + + /// Check if the console is allowed to enter the home menu. + /// + /// You can set whether the console is allowed to enter the home menu with [Apt::set_home_allowed]. + #[doc(alias = "aptIsHomeAllowed")] + pub fn is_home_allowed(&mut self) -> bool { + unsafe { + ctru_sys::aptIsHomeAllowed() + } + } + + /// Immediately jumps to the home menu. + #[doc(alias = "aptIsHomeAllowed")] + pub fn jump_to_home_menu(&mut self) { + unsafe { + ctru_sys::aptJumpToHomeMenu() + } + } } impl Drop for Apt { From 4f3562b5235a39de258f1b54aadbbb36f76e3c57 Mon Sep 17 00:00:00 2001 From: Lena Date: Sat, 17 Feb 2024 02:31:37 +0100 Subject: [PATCH 2/9] cargo fmt --- ctru-rs/src/services/apt.rs | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/ctru-rs/src/services/apt.rs b/ctru-rs/src/services/apt.rs index ef09527..09892df 100644 --- a/ctru-rs/src/services/apt.rs +++ b/ctru-rs/src/services/apt.rs @@ -98,9 +98,7 @@ impl Apt { /// You can set whether the console is allowed to sleep with [Apt::set_sleep_allowed]. #[doc(alias = "aptIsSleepAllowed")] pub fn is_sleep_allowed(&mut self) -> bool { - unsafe { - ctru_sys::aptIsSleepAllowed() - } + unsafe { ctru_sys::aptIsSleepAllowed() } } /// Set if the console is allowed to enter the home menu. @@ -114,21 +112,17 @@ impl Apt { } /// Check if the console is allowed to enter the home menu. - /// + /// /// You can set whether the console is allowed to enter the home menu with [Apt::set_home_allowed]. #[doc(alias = "aptIsHomeAllowed")] pub fn is_home_allowed(&mut self) -> bool { - unsafe { - ctru_sys::aptIsHomeAllowed() - } + unsafe { ctru_sys::aptIsHomeAllowed() } } /// Immediately jumps to the home menu. #[doc(alias = "aptIsHomeAllowed")] pub fn jump_to_home_menu(&mut self) { - unsafe { - ctru_sys::aptJumpToHomeMenu() - } + unsafe { ctru_sys::aptJumpToHomeMenu() } } } From cc2e535e9655c81cb451837c8f3d029c6223ec8a Mon Sep 17 00:00:00 2001 From: Lena Date: Sat, 17 Feb 2024 16:44:18 +0100 Subject: [PATCH 3/9] fix apt mutability requirements --- ctru-rs/src/services/apt.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ctru-rs/src/services/apt.rs b/ctru-rs/src/services/apt.rs index 09892df..2a3b7fb 100644 --- a/ctru-rs/src/services/apt.rs +++ b/ctru-rs/src/services/apt.rs @@ -97,7 +97,7 @@ impl Apt { /// /// You can set whether the console is allowed to sleep with [Apt::set_sleep_allowed]. #[doc(alias = "aptIsSleepAllowed")] - pub fn is_sleep_allowed(&mut self) -> bool { + pub fn is_sleep_allowed(&self) -> bool { unsafe { ctru_sys::aptIsSleepAllowed() } } @@ -115,7 +115,7 @@ impl Apt { /// /// You can set whether the console is allowed to enter the home menu with [Apt::set_home_allowed]. #[doc(alias = "aptIsHomeAllowed")] - pub fn is_home_allowed(&mut self) -> bool { + pub fn is_home_allowed(&self) -> bool { unsafe { ctru_sys::aptIsHomeAllowed() } } From e2364ff5e182cc264befc3628df2d15e771553e6 Mon Sep 17 00:00:00 2001 From: Lena Date: Sat, 17 Feb 2024 16:42:31 +0100 Subject: [PATCH 4/9] implement chainloader --- ctru-rs/src/services/am.rs | 5 +++++ ctru-rs/src/services/apt.rs | 41 +++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/ctru-rs/src/services/am.rs b/ctru-rs/src/services/am.rs index f4b6e6a..2bcd47a 100644 --- a/ctru-rs/src/services/am.rs +++ b/ctru-rs/src/services/am.rs @@ -51,6 +51,11 @@ impl<'a> Title<'a> { pub fn version(&self) -> u16 { self.version } + + /// Returns this title's media type + pub fn media_type(&self) -> MediaType { + self.mediatype + } } /// Handle to the Application Manager service. diff --git a/ctru-rs/src/services/apt.rs b/ctru-rs/src/services/apt.rs index 2a3b7fb..5df178b 100644 --- a/ctru-rs/src/services/apt.rs +++ b/ctru-rs/src/services/apt.rs @@ -132,3 +132,44 @@ impl Drop for Apt { unsafe { ctru_sys::aptExit() }; } } + +pub struct Chainloader<'a> { + _apt: &'a Apt, +} + +impl<'a> Chainloader<'a> { + /// Gets a handle to the chainloader + pub fn new(apt: &'a Apt) -> Self { + Self { _apt: apt } + } + + /// Checks if the chainloader is set + #[doc(alias = "aptIsChainload")] + pub fn is_set(&mut self) { + //unsafe { ctru_sys::aptIsChainload() } + } + + /// Clears the chainloader state. + #[doc(alias = "aptClearChainloader")] + pub fn clear(&mut self) { + unsafe { ctru_sys::aptClearChainloader() } + } + + /// Configures the chainloader to launch a specific application. + #[doc(alias = "aptSetChainloader")] + pub fn set_chainloader(&mut self, title: &super::am::Title<'_>) { + unsafe { ctru_sys::aptSetChainloader(title.id(), title.media_type() as u8) } + } + + /// Configures the chainloader to launch the previous application. + #[doc(alias = "aptSetChainloaderToCaller")] + pub fn set_chainloader_to_caller(&mut self) { + unsafe { ctru_sys::aptSetChainloaderToCaller() } + } + + /// Configures the chainloader to relaunch the current application (i.e. soft-reset) + #[doc(alias = "aptSetChainloaderToSelf")] + pub fn set_chainloader_to_self(&mut self) { + unsafe { ctru_sys::aptSetChainloaderToSelf() } + } +} From 66e5a54952d48dd5de85129191cf9c90db703fc8 Mon Sep 17 00:00:00 2001 From: Lena Date: Sat, 17 Feb 2024 16:50:20 +0100 Subject: [PATCH 5/9] add simple doc for chainloader --- ctru-rs/src/services/apt.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/ctru-rs/src/services/apt.rs b/ctru-rs/src/services/apt.rs index 5df178b..fa26470 100644 --- a/ctru-rs/src/services/apt.rs +++ b/ctru-rs/src/services/apt.rs @@ -133,6 +133,7 @@ impl Drop for Apt { } } +/// Can launch other applications when the current one exits. pub struct Chainloader<'a> { _apt: &'a Apt, } From 0c55e1ef9b531584c2ea38f3e926bf1920bba8c8 Mon Sep 17 00:00:00 2001 From: Lena Date: Sat, 17 Feb 2024 20:26:09 +0100 Subject: [PATCH 6/9] fix chainloader --- ctru-rs/src/services/apt.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ctru-rs/src/services/apt.rs b/ctru-rs/src/services/apt.rs index fa26470..6bbe075 100644 --- a/ctru-rs/src/services/apt.rs +++ b/ctru-rs/src/services/apt.rs @@ -146,8 +146,9 @@ impl<'a> Chainloader<'a> { /// Checks if the chainloader is set #[doc(alias = "aptIsChainload")] - pub fn is_set(&mut self) { - //unsafe { ctru_sys::aptIsChainload() } + pub fn is_set(&self) -> bool { + // static funtion not exported + unsafe { (ctru_sys::envGetSystemRunFlags() & ctru_sys::RUNFLAG_APTCHAINLOAD) != 0 } } /// Clears the chainloader state. From f780bcedbb5593849002929a641ca9c8e70790c6 Mon Sep 17 00:00:00 2001 From: Lena Date: Mon, 19 Feb 2024 23:37:27 +0100 Subject: [PATCH 7/9] fix review issues --- ctru-rs/src/services/apt.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ctru-rs/src/services/apt.rs b/ctru-rs/src/services/apt.rs index 6bbe075..a391b47 100644 --- a/ctru-rs/src/services/apt.rs +++ b/ctru-rs/src/services/apt.rs @@ -120,7 +120,7 @@ impl Apt { } /// Immediately jumps to the home menu. - #[doc(alias = "aptIsHomeAllowed")] + #[doc(alias = "aptJumpToHomeMenu")] pub fn jump_to_home_menu(&mut self) { unsafe { ctru_sys::aptJumpToHomeMenu() } } @@ -159,19 +159,19 @@ impl<'a> Chainloader<'a> { /// Configures the chainloader to launch a specific application. #[doc(alias = "aptSetChainloader")] - pub fn set_chainloader(&mut self, title: &super::am::Title<'_>) { + pub fn set(&mut self, title: &super::am::Title<'_>) { unsafe { ctru_sys::aptSetChainloader(title.id(), title.media_type() as u8) } } /// Configures the chainloader to launch the previous application. #[doc(alias = "aptSetChainloaderToCaller")] - pub fn set_chainloader_to_caller(&mut self) { + pub fn set_to_caller(&mut self) { unsafe { ctru_sys::aptSetChainloaderToCaller() } } /// Configures the chainloader to relaunch the current application (i.e. soft-reset) #[doc(alias = "aptSetChainloaderToSelf")] - pub fn set_chainloader_to_self(&mut self) { + pub fn set_to_self(&mut self) { unsafe { ctru_sys::aptSetChainloaderToSelf() } } } From e6dddff3c369451d1d6b234034ff6e7c6f04c50d Mon Sep 17 00:00:00 2001 From: Lena Date: Fri, 23 Feb 2024 01:34:58 +0100 Subject: [PATCH 8/9] add "see also" --- ctru-rs/src/services/apt.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ctru-rs/src/services/apt.rs b/ctru-rs/src/services/apt.rs index a391b47..e97f55f 100644 --- a/ctru-rs/src/services/apt.rs +++ b/ctru-rs/src/services/apt.rs @@ -158,6 +158,8 @@ impl<'a> Chainloader<'a> { } /// Configures the chainloader to launch a specific application. + /// + /// See also [super::am::Title] #[doc(alias = "aptSetChainloader")] pub fn set(&mut self, title: &super::am::Title<'_>) { unsafe { ctru_sys::aptSetChainloader(title.id(), title.media_type() as u8) } From 80853b2238265d70dbf23a9fd4b37608089300fe Mon Sep 17 00:00:00 2001 From: Lena Date: Fri, 23 Feb 2024 20:53:55 +0100 Subject: [PATCH 9/9] Apply apt review suggestion Co-authored-by: Meziu <55318903+Meziu@users.noreply.github.com> --- ctru-rs/src/services/apt.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ctru-rs/src/services/apt.rs b/ctru-rs/src/services/apt.rs index e97f55f..e1f1f57 100644 --- a/ctru-rs/src/services/apt.rs +++ b/ctru-rs/src/services/apt.rs @@ -159,7 +159,7 @@ impl<'a> Chainloader<'a> { /// Configures the chainloader to launch a specific application. /// - /// See also [super::am::Title] + /// See also [`Title`](crate::services::am::Title] #[doc(alias = "aptSetChainloader")] pub fn set(&mut self, title: &super::am::Title<'_>) { unsafe { ctru_sys::aptSetChainloader(title.id(), title.media_type() as u8) }