Skip to content

Commit eed5fc9

Browse files
Merge pull request #161 from adryzz/apt-new-stuff
2 parents 10163fd + 80853b2 commit eed5fc9

2 files changed

Lines changed: 92 additions & 0 deletions

File tree

ctru-rs/src/services/am.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ impl<'a> Title<'a> {
5151
pub fn version(&self) -> u16 {
5252
self.version
5353
}
54+
55+
/// Returns this title's media type
56+
pub fn media_type(&self) -> MediaType {
57+
self.mediatype
58+
}
5459
}
5560

5661
/// Handle to the Application Manager service.

ctru-rs/src/services/apt.rs

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,48 @@ impl Apt {
8282
Ok(())
8383
}
8484
}
85+
86+
/// Set if the console is allowed to enter sleep mode.
87+
///
88+
/// You can check whether the console is allowed to sleep with [Apt::is_sleep_allowed].
89+
#[doc(alias = "aptSetSleepAllowed")]
90+
pub fn set_sleep_allowed(&mut self, allowed: bool) {
91+
unsafe {
92+
ctru_sys::aptSetSleepAllowed(allowed);
93+
}
94+
}
95+
96+
/// Check if the console is allowed to enter sleep mode.
97+
///
98+
/// You can set whether the console is allowed to sleep with [Apt::set_sleep_allowed].
99+
#[doc(alias = "aptIsSleepAllowed")]
100+
pub fn is_sleep_allowed(&self) -> bool {
101+
unsafe { ctru_sys::aptIsSleepAllowed() }
102+
}
103+
104+
/// Set if the console is allowed to enter the home menu.
105+
///
106+
/// You can check whether the console is allowed to enter the home menu with [Apt::is_home_allowed].
107+
#[doc(alias = "aptSetHomeAllowed")]
108+
pub fn set_home_allowed(&mut self, allowed: bool) {
109+
unsafe {
110+
ctru_sys::aptSetHomeAllowed(allowed);
111+
}
112+
}
113+
114+
/// Check if the console is allowed to enter the home menu.
115+
///
116+
/// You can set whether the console is allowed to enter the home menu with [Apt::set_home_allowed].
117+
#[doc(alias = "aptIsHomeAllowed")]
118+
pub fn is_home_allowed(&self) -> bool {
119+
unsafe { ctru_sys::aptIsHomeAllowed() }
120+
}
121+
122+
/// Immediately jumps to the home menu.
123+
#[doc(alias = "aptJumpToHomeMenu")]
124+
pub fn jump_to_home_menu(&mut self) {
125+
unsafe { ctru_sys::aptJumpToHomeMenu() }
126+
}
85127
}
86128

87129
impl Drop for Apt {
@@ -90,3 +132,48 @@ impl Drop for Apt {
90132
unsafe { ctru_sys::aptExit() };
91133
}
92134
}
135+
136+
/// Can launch other applications when the current one exits.
137+
pub struct Chainloader<'a> {
138+
_apt: &'a Apt,
139+
}
140+
141+
impl<'a> Chainloader<'a> {
142+
/// Gets a handle to the chainloader
143+
pub fn new(apt: &'a Apt) -> Self {
144+
Self { _apt: apt }
145+
}
146+
147+
/// Checks if the chainloader is set
148+
#[doc(alias = "aptIsChainload")]
149+
pub fn is_set(&self) -> bool {
150+
// static funtion not exported
151+
unsafe { (ctru_sys::envGetSystemRunFlags() & ctru_sys::RUNFLAG_APTCHAINLOAD) != 0 }
152+
}
153+
154+
/// Clears the chainloader state.
155+
#[doc(alias = "aptClearChainloader")]
156+
pub fn clear(&mut self) {
157+
unsafe { ctru_sys::aptClearChainloader() }
158+
}
159+
160+
/// Configures the chainloader to launch a specific application.
161+
///
162+
/// See also [`Title`](crate::services::am::Title]
163+
#[doc(alias = "aptSetChainloader")]
164+
pub fn set(&mut self, title: &super::am::Title<'_>) {
165+
unsafe { ctru_sys::aptSetChainloader(title.id(), title.media_type() as u8) }
166+
}
167+
168+
/// Configures the chainloader to launch the previous application.
169+
#[doc(alias = "aptSetChainloaderToCaller")]
170+
pub fn set_to_caller(&mut self) {
171+
unsafe { ctru_sys::aptSetChainloaderToCaller() }
172+
}
173+
174+
/// Configures the chainloader to relaunch the current application (i.e. soft-reset)
175+
#[doc(alias = "aptSetChainloaderToSelf")]
176+
pub fn set_to_self(&mut self) {
177+
unsafe { ctru_sys::aptSetChainloaderToSelf() }
178+
}
179+
}

0 commit comments

Comments
 (0)