From a68568498824534ab10d929041cfd259d508abf1 Mon Sep 17 00:00:00 2001 From: Xavier Chapron Date: Thu, 14 Dec 2023 18:17:37 +0100 Subject: [PATCH] ui:gadgets.rs: Add display_pending_review() --- ledger_device_sdk/Cargo.toml | 2 +- ledger_device_sdk/src/ui/gadgets.rs | 49 +++++++++++++++++++++++++++-- 2 files changed, 48 insertions(+), 3 deletions(-) diff --git a/ledger_device_sdk/Cargo.toml b/ledger_device_sdk/Cargo.toml index 514e3505..09d52ff2 100644 --- a/ledger_device_sdk/Cargo.toml +++ b/ledger_device_sdk/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ledger_device_sdk" -version = "1.2.1" +version = "1.3.0" authors = ["yhql", "yogh333"] edition = "2021" license.workspace = true diff --git a/ledger_device_sdk/src/ui/gadgets.rs b/ledger_device_sdk/src/ui/gadgets.rs index cf94a6d9..e8f99818 100644 --- a/ledger_device_sdk/src/ui/gadgets.rs +++ b/ledger_device_sdk/src/ui/gadgets.rs @@ -4,14 +4,14 @@ use core::str::from_utf8; use crate::{ buttons::ButtonEvent::*, - io::{self, ApduHeader, Reply}, + io::{self, ApduHeader, Comm, Event, Reply}, }; use ledger_secure_sdk_sys::{ buttons::{get_button_event, ButtonEvent, ButtonsState}, seph, }; -use crate::ui::bitmaps::Glyph; +use crate::ui::bitmaps::{Glyph, WARNING}; use crate::ui::{bagls::*, fonts::OPEN_SANS}; @@ -66,6 +66,51 @@ pub fn clear_screen() { BLANK.paint(); } +/// Display a developer mode / pending review popup, cleared with user interaction. +/// +/// This method must be called by an application at the very beginning until it has been reviewed +/// and approved by Ledger. +/// +/// # Arguments +/// +/// * `comm` - Communication manager used to get device events. +/// +/// # Examples +/// +/// Following is an application example main function calling the pending review popup at the very +/// beginning, before doing any other application logic. +/// +/// ``` +/// #[no_mangle] +/// extern "C" fn sample_main() { +/// let mut comm = Comm::new(); +/// ledger_device_sdk::ui::gadgets::display_pending_review(&mut comm); +/// ... +/// } +/// ` +pub fn display_pending_review(comm: &mut Comm) { + clear_screen(); + + // Add icon and text to match the C SDK equivalent. + if cfg!(target_os = "nanos") { + "Pending".place(Location::Custom(2), Layout::Centered, true); + "Ledger review".place(Location::Custom(14), Layout::Centered, true); + } else { + WARNING.draw(57, 10); + "Pending".place(Location::Custom(28), Layout::Centered, true); + "Ledger review".place(Location::Custom(42), Layout::Centered, true); + } + + crate::ui::screen_util::screen_update(); + + // Process events until a double button press release. + loop { + if let Event::Button(BothButtonsRelease) = comm.next_event::() { + break; + } + } +} + /// Shorthand to display a single message /// and wait for button action pub fn popup(message: &str) {