Browse Source

Move error parsing code into launch_unchecked

pull/162/head
Fenrir 11 months ago
parent
commit
efbf913380
  1. 23
      ctru-rs/src/applets/error.rs

23
ctru-rs/src/applets/error.rs

@ -1,6 +1,7 @@ @@ -1,6 +1,7 @@
//! Error applet
//!
//! This applet displays error text as a pop-up message on the lower screen.
use crate::services::{apt::Apt, gfx::Gfx};
use ctru_sys::errorConf;
@ -66,7 +67,16 @@ impl PopUp { @@ -66,7 +67,16 @@ impl PopUp {
/// Launches the error applet.
#[doc(alias = "errorDisp")]
pub fn launch(&mut self, _apt: &Apt, _gfx: &Gfx) -> Result<(), Error> {
unsafe { ctru_sys::errorDisp(self.state.as_mut()) }
unsafe { self.launch_unchecked() }
}
/// Launches the error applet without requiring an [`Apt`] or [`Gfx`] handle.
///
/// # Safety
///
/// Causes undefined behavior if the aforementioned services are not actually active when the applet launches.
unsafe fn launch_unchecked(&mut self) -> Result<(), Error> {
unsafe { ctru_sys::errorDisp(self.state.as_mut()) };
match self.state.returnCode {
ctru_sys::ERROR_NONE | ctru_sys::ERROR_SUCCESS => Ok(()),
@ -77,15 +87,6 @@ impl PopUp { @@ -77,15 +87,6 @@ impl PopUp {
_ => Err(Error::Unknown),
}
}
/// Launches the error applet without requiring an [`Apt`] or [`Gfx`] handle.
///
/// # Safety
///
/// Causes undefined behavior if the aforementioned services are not actually active when the applet launches.
unsafe fn launch_unchecked(&mut self) {
unsafe { ctru_sys::errorDisp(self.state.as_mut()) };
}
}
/// Sets a custom [panic hook](https://doc.rust-lang.org/std/panic/fn.set_hook.html) that uses the error applet to display panic messages.
@ -123,7 +124,7 @@ pub fn set_panic_hook(call_old_hook: bool) { @@ -123,7 +124,7 @@ pub fn set_panic_hook(call_old_hook: bool) {
popup.set_text(&payload);
unsafe {
popup.launch_unchecked();
let _ = popup.launch_unchecked();
}
} else {
old_hook(panic_info);

Loading…
Cancel
Save