1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-26 01:18:28 +00:00

refactor(core): move show_wait_text to UiFeatures

This commit is contained in:
obrusvit 2024-10-31 14:44:48 +01:00
parent e82988665c
commit 160e6be4b9
13 changed files with 43 additions and 56 deletions

View File

@ -248,6 +248,17 @@ extern "C" fn new_show_lockscreen(n_args: usize, args: *const Obj, kwargs: *mut
unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) } unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) }
} }
extern "C" fn new_show_wait_text(message: Obj) -> Obj {
let block = || {
let message: TString<'static> = message.try_into()?;
let layout = ModelUI::show_wait_text(message)?;
Ok(LayoutObj::new_root(layout)?.into())
};
unsafe { util::try_or_raise(block) }
}
pub extern "C" fn upy_check_homescreen_format(data: Obj) -> Obj { pub extern "C" fn upy_check_homescreen_format(data: Obj) -> Obj {
let block = || { let block = || {
let buffer = data.try_into()?; let buffer = data.try_into()?;
@ -486,6 +497,10 @@ pub static mp_module_trezorui_api: Module = obj_module! {
/// """Homescreen for locked device.""" /// """Homescreen for locked device."""
Qstr::MP_QSTR_show_lockscreen => obj_fn_kw!(0, new_show_lockscreen).as_obj(), Qstr::MP_QSTR_show_lockscreen => obj_fn_kw!(0, new_show_lockscreen).as_obj(),
/// def show_wait_text(message: str, /) -> LayoutObj[None]:
/// """Show single-line text in the middle of the screen."""
Qstr::MP_QSTR_show_wait_text => obj_fn_1!(new_show_wait_text).as_obj(),
/// class BacklightLevels: /// class BacklightLevels:
/// """Backlight levels. Values dynamically update based on user settings.""" /// """Backlight levels. Values dynamically update based on user settings."""
/// MAX: ClassVar[int] /// MAX: ClassVar[int]

View File

@ -1208,15 +1208,6 @@ extern "C" fn new_show_progress_coinjoin(n_args: usize, args: *const Obj, kwargs
unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) } unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) }
} }
extern "C" fn new_show_wait_text(message: Obj) -> Obj {
let block = || {
let message: TString<'static> = message.try_into()?;
Ok(LayoutObj::new(Connect::new(message, theme::FG, theme::BG))?.into())
};
unsafe { util::try_or_raise(block) }
}
extern "C" fn new_confirm_fido(n_args: usize, args: *const Obj, kwargs: *mut Map) -> Obj { extern "C" fn new_confirm_fido(n_args: usize, args: *const Obj, kwargs: *mut Map) -> Obj {
#[cfg(feature = "universal_fw")] #[cfg(feature = "universal_fw")]
return flow::confirm_fido::new_confirm_fido(n_args, args, kwargs); return flow::confirm_fido::new_confirm_fido(n_args, args, kwargs);
@ -1547,10 +1538,6 @@ pub static mp_module_trezorui2: Module = obj_module! {
/// """Show user how to interact with the device.""" /// """Show user how to interact with the device."""
Qstr::MP_QSTR_tutorial => obj_fn_0!(new_show_tutorial).as_obj(), Qstr::MP_QSTR_tutorial => obj_fn_0!(new_show_tutorial).as_obj(),
/// def show_wait_text(message: str, /) -> LayoutObj[None]:
/// """Show single-line text in the middle of the screen."""
Qstr::MP_QSTR_show_wait_text => obj_fn_1!(new_show_wait_text).as_obj(),
/// def flow_get_address( /// def flow_get_address(
/// *, /// *,
/// address: str | bytes, /// address: str | bytes,

View File

@ -6,6 +6,7 @@ use crate::{
translations::TR, translations::TR,
ui::{ ui::{
component::{ component::{
connect::Connect,
swipe_detect::SwipeSettings, swipe_detect::SwipeSettings,
text::paragraphs::{Paragraph, ParagraphSource, ParagraphVecShort, Paragraphs}, text::paragraphs::{Paragraph, ParagraphSource, ParagraphVecShort, Paragraphs},
CachedJpeg, CachedJpeg,
@ -220,4 +221,9 @@ impl UIFeaturesFirmware for ModelMercuryFeatures {
let layout = RootComponent::new(Lockscreen::new(label, bootscreen, coinjoin_authorized)); let layout = RootComponent::new(Lockscreen::new(label, bootscreen, coinjoin_authorized));
Ok(layout) Ok(layout)
} }
fn show_wait_text(text: TString<'static>) -> Result<impl LayoutMaybeTrace, Error> {
let layout = RootComponent::new(Connect::new(text, theme::FG, theme::BG));
Ok(layout)
}
} }

View File

@ -1371,16 +1371,6 @@ extern "C" fn new_show_progress_coinjoin(n_args: usize, args: *const Obj, kwargs
unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) } unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) }
} }
extern "C" fn new_show_wait_text(message: Obj) -> Obj {
let block = || {
let message: TString<'static> = message.try_into()?;
let obj = LayoutObj::new(Connect::new(message, theme::FG, theme::BG))?;
Ok(obj.into())
};
unsafe { util::try_or_raise(block) }
}
#[no_mangle] #[no_mangle]
pub static mp_module_trezorui2: Module = obj_module! { pub static mp_module_trezorui2: Module = obj_module! {
/// from trezor import utils /// from trezor import utils
@ -1679,8 +1669,4 @@ pub static mp_module_trezorui2: Module = obj_module! {
/// """Show progress loader for coinjoin. Returns CANCELLED after a specified time when /// """Show progress loader for coinjoin. Returns CANCELLED after a specified time when
/// time_ms timeout is passed.""" /// time_ms timeout is passed."""
Qstr::MP_QSTR_show_progress_coinjoin => obj_fn_kw!(0, new_show_progress_coinjoin).as_obj(), Qstr::MP_QSTR_show_progress_coinjoin => obj_fn_kw!(0, new_show_progress_coinjoin).as_obj(),
/// def show_wait_text(message: str, /) -> None:
/// """Show single-line text in the middle of the screen."""
Qstr::MP_QSTR_show_wait_text => obj_fn_1!(new_show_wait_text).as_obj(),
}; };

View File

@ -7,8 +7,7 @@ use crate::{
translations::TR, translations::TR,
ui::{ ui::{
component::{ component::{
text::paragraphs::{Paragraph, ParagraphSource, ParagraphVecShort, Paragraphs, VecExt}, connect::Connect, text::paragraphs::{Paragraph, ParagraphSource, ParagraphVecShort, Paragraphs, VecExt}, Component, ComponentExt, Label, LineBreaking, Paginate, Timeout
Component, ComponentExt, Label, LineBreaking, Paginate, Timeout,
}, },
layout::{ layout::{
obj::{LayoutMaybeTrace, LayoutObj, RootComponent}, obj::{LayoutMaybeTrace, LayoutObj, RootComponent},
@ -245,6 +244,11 @@ impl UIFeaturesFirmware for ModelTRFeatures {
let layout = RootComponent::new(Lockscreen::new(label, bootscreen, coinjoin_authorized)); let layout = RootComponent::new(Lockscreen::new(label, bootscreen, coinjoin_authorized));
Ok(layout) Ok(layout)
} }
fn show_wait_text(text: TString<'static>) -> Result<impl LayoutMaybeTrace, Error> {
let layout = RootComponent::new(Connect::new(text, theme::FG, theme::BG));
Ok(layout)
}
} }
/// Function to create and call a `ButtonPage` dialog based on paginable content /// Function to create and call a `ButtonPage` dialog based on paginable content

View File

@ -1349,16 +1349,6 @@ extern "C" fn new_show_progress_coinjoin(n_args: usize, args: *const Obj, kwargs
unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) } unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) }
} }
extern "C" fn new_show_wait_text(message: Obj) -> Obj {
let block = || {
let message: TString<'static> = message.try_into()?;
let obj = LayoutObj::new(Connect::new(message, theme::FG, theme::BG))?;
Ok(obj.into())
};
unsafe { util::try_or_raise(block) }
}
#[no_mangle] #[no_mangle]
pub static mp_module_trezorui2: Module = obj_module! { pub static mp_module_trezorui2: Module = obj_module! {
/// from trezor import utils /// from trezor import utils
@ -1663,10 +1653,6 @@ pub static mp_module_trezorui2: Module = obj_module! {
/// """Show progress loader for coinjoin. Returns CANCELLED after a specified time when /// """Show progress loader for coinjoin. Returns CANCELLED after a specified time when
/// time_ms timeout is passed.""" /// time_ms timeout is passed."""
Qstr::MP_QSTR_show_progress_coinjoin => obj_fn_kw!(0, new_show_progress_coinjoin).as_obj(), Qstr::MP_QSTR_show_progress_coinjoin => obj_fn_kw!(0, new_show_progress_coinjoin).as_obj(),
/// def show_wait_text(message: str, /) -> LayoutObj[None]:
/// """Show single-line text in the middle of the screen."""
Qstr::MP_QSTR_show_wait_text => obj_fn_1!(new_show_wait_text).as_obj(),
}; };
#[cfg(test)] #[cfg(test)]

View File

@ -6,6 +6,7 @@ use crate::{
translations::TR, translations::TR,
ui::{ ui::{
component::{ component::{
connect::Connect,
image::BlendedImage, image::BlendedImage,
text::paragraphs::{Paragraph, ParagraphSource, ParagraphVecShort, Paragraphs, VecExt}, text::paragraphs::{Paragraph, ParagraphSource, ParagraphVecShort, Paragraphs, VecExt},
ComponentExt, Empty, Jpeg, Label, Timeout, ComponentExt, Empty, Jpeg, Label, Timeout,
@ -271,6 +272,11 @@ impl UIFeaturesFirmware for ModelTTFeatures {
let layout = RootComponent::new(Lockscreen::new(label, bootscreen, coinjoin_authorized)); let layout = RootComponent::new(Lockscreen::new(label, bootscreen, coinjoin_authorized));
Ok(layout) Ok(layout)
} }
fn show_wait_text(text: TString<'static>) -> Result<impl LayoutMaybeTrace, Error> {
let layout = RootComponent::new(Connect::new(text, theme::FG, theme::BG));
Ok(layout)
}
} }
fn new_show_modal( fn new_show_modal(

View File

@ -85,4 +85,6 @@ pub trait UIFeaturesFirmware {
bootscreen: bool, bootscreen: bool,
coinjoin_authorized: bool, coinjoin_authorized: bool,
) -> Result<impl LayoutMaybeTrace, Error>; ) -> Result<impl LayoutMaybeTrace, Error>;
fn show_wait_text(text: TString<'static>) -> Result<impl LayoutMaybeTrace, Error>;
} }

View File

@ -329,11 +329,6 @@ def tutorial() -> LayoutObj[UiResult]:
"""Show user how to interact with the device.""" """Show user how to interact with the device."""
# rust/src/ui/model_mercury/layout.rs
def show_wait_text(message: str, /) -> LayoutObj[None]:
"""Show single-line text in the middle of the screen."""
# rust/src/ui/model_mercury/layout.rs # rust/src/ui/model_mercury/layout.rs
def flow_get_address( def flow_get_address(
*, *,
@ -1058,8 +1053,3 @@ def show_progress_coinjoin(
) -> LayoutObj[UiResult]: ) -> LayoutObj[UiResult]:
"""Show progress loader for coinjoin. Returns CANCELLED after a specified time when """Show progress loader for coinjoin. Returns CANCELLED after a specified time when
time_ms timeout is passed.""" time_ms timeout is passed."""
# rust/src/ui/model_tt/layout.rs
def show_wait_text(message: str, /) -> LayoutObj[None]:
"""Show single-line text in the middle of the screen."""

View File

@ -216,6 +216,11 @@ def show_lockscreen(
"""Homescreen for locked device.""" """Homescreen for locked device."""
# rust/src/ui/api/firmware_upy.rs
def show_wait_text(message: str, /) -> LayoutObj[None]:
"""Show single-line text in the middle of the screen."""
# rust/src/ui/api/firmware_upy.rs # rust/src/ui/api/firmware_upy.rs
class BacklightLevels: class BacklightLevels:
"""Backlight levels. Values dynamically update based on user settings.""" """Backlight levels. Values dynamically update based on user settings."""

View File

@ -1090,7 +1090,7 @@ def request_passphrase_on_host() -> None:
def show_wait_text(message: str) -> None: def show_wait_text(message: str) -> None:
draw_simple(trezorui2.show_wait_text(message)) draw_simple(trezorui_api.show_wait_text(message))
def request_passphrase_on_device(max_len: int) -> Awaitable[str]: def request_passphrase_on_device(max_len: int) -> Awaitable[str]:

View File

@ -1148,7 +1148,7 @@ def request_passphrase_on_host() -> None:
def show_wait_text(message: str) -> None: def show_wait_text(message: str) -> None:
draw_simple(trezorui2.show_wait_text(message)) draw_simple(trezorui_api.show_wait_text(message))
async def request_passphrase_on_device(max_len: int) -> str: async def request_passphrase_on_device(max_len: int) -> str:

View File

@ -1149,7 +1149,7 @@ def request_passphrase_on_host() -> None:
def show_wait_text(message: str) -> None: def show_wait_text(message: str) -> None:
draw_simple(trezorui2.show_wait_text(message)) draw_simple(trezorui_api.show_wait_text(message))
async def request_passphrase_on_device(max_len: int) -> str: async def request_passphrase_on_device(max_len: int) -> str: