1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-07-01 12:22:34 +00:00

refactor(core): cleanup homescreen params

- rename FirmwareUI::show_homescreen param name from `hold` to
  `lockable` because hold or hold_to_lock no longer covers all layouts
- cleanup uPy notification params

[no changelog]
This commit is contained in:
obrusvit 2025-06-11 22:41:35 +02:00 committed by Vít Obrusník
parent 5104872010
commit 2196a5f785
10 changed files with 27 additions and 34 deletions

View File

@ -361,6 +361,7 @@ static void _librust_qstrs(void) {
MP_QSTR_language__title; MP_QSTR_language__title;
MP_QSTR_lines; MP_QSTR_lines;
MP_QSTR_load_from_flash; MP_QSTR_load_from_flash;
MP_QSTR_lockable;
MP_QSTR_lockscreen__tap_to_connect; MP_QSTR_lockscreen__tap_to_connect;
MP_QSTR_lockscreen__tap_to_unlock; MP_QSTR_lockscreen__tap_to_unlock;
MP_QSTR_lockscreen__title_locked; MP_QSTR_lockscreen__title_locked;

View File

@ -825,10 +825,10 @@ extern "C" fn new_show_homescreen(n_args: usize, args: *const Obj, kwargs: *mut
let notification: Option<TString<'static>> = let notification: Option<TString<'static>> =
kwargs.get(Qstr::MP_QSTR_notification)?.try_into_option()?; kwargs.get(Qstr::MP_QSTR_notification)?.try_into_option()?;
let notification_level: u8 = kwargs.get_or(Qstr::MP_QSTR_notification_level, 0)?; let notification_level: u8 = kwargs.get_or(Qstr::MP_QSTR_notification_level, 0)?;
let hold: bool = kwargs.get(Qstr::MP_QSTR_hold)?.try_into()?; let lockable: bool = kwargs.get(Qstr::MP_QSTR_lockable)?.try_into()?;
let skip_first_paint: bool = kwargs.get(Qstr::MP_QSTR_skip_first_paint)?.try_into()?; let skip_first_paint: bool = kwargs.get(Qstr::MP_QSTR_skip_first_paint)?.try_into()?;
let layout = ModelUI::show_homescreen(label, hold, notification, notification_level)?; let layout = ModelUI::show_homescreen(label, notification, notification_level, lockable)?;
let layout_obj = LayoutObj::new_root(layout)?; let layout_obj = LayoutObj::new_root(layout)?;
if skip_first_paint { if skip_first_paint {
layout_obj.skip_first_paint(); layout_obj.skip_first_paint();
@ -1662,9 +1662,9 @@ pub static mp_module_trezorui_api: Module = obj_module! {
/// def show_homescreen( /// def show_homescreen(
/// *, /// *,
/// label: str | None, /// label: str | None,
/// hold: bool,
/// notification: str | None, /// notification: str | None,
/// notification_level: int = 0, /// notification_level: int = 0,
/// lockable: bool,
/// skip_first_paint: bool, /// skip_first_paint: bool,
/// ) -> LayoutObj[UiResult]: /// ) -> LayoutObj[UiResult]:
/// """Idle homescreen.""" /// """Idle homescreen."""

View File

@ -869,12 +869,12 @@ impl FirmwareUI for UIBolt {
fn show_homescreen( fn show_homescreen(
label: TString<'static>, label: TString<'static>,
hold: bool,
notification: Option<TString<'static>>, notification: Option<TString<'static>>,
notification_level: u8, notification_level: u8,
lockable: bool,
) -> Result<impl LayoutMaybeTrace, Error> { ) -> Result<impl LayoutMaybeTrace, Error> {
let notification = notification.map(|w| (w, notification_level)); let notification = notification.map(|w| (w, notification_level));
let layout = RootComponent::new(Homescreen::new(label, notification, hold)); let layout = RootComponent::new(Homescreen::new(label, notification, lockable));
Ok(layout) Ok(layout)
} }

View File

@ -1059,12 +1059,12 @@ impl FirmwareUI for UICaesar {
fn show_homescreen( fn show_homescreen(
label: TString<'static>, label: TString<'static>,
hold: bool,
notification: Option<TString<'static>>, notification: Option<TString<'static>>,
notification_level: u8, notification_level: u8,
lockable: bool,
) -> Result<impl LayoutMaybeTrace, Error> { ) -> Result<impl LayoutMaybeTrace, Error> {
let notification = notification.map(|w| (w, notification_level)); let notification = notification.map(|w| (w, notification_level));
let loader_description = hold.then_some("Locking the device...".into()); let loader_description = lockable.then_some("Locking the device...".into());
let layout = RootComponent::new(Homescreen::new(label, notification, loader_description)); let layout = RootComponent::new(Homescreen::new(label, notification, loader_description));
Ok(layout) Ok(layout)
} }

View File

@ -889,12 +889,12 @@ impl FirmwareUI for UIDelizia {
fn show_homescreen( fn show_homescreen(
label: TString<'static>, label: TString<'static>,
hold: bool,
notification: Option<TString<'static>>, notification: Option<TString<'static>>,
notification_level: u8, notification_level: u8,
lockable: bool,
) -> Result<impl LayoutMaybeTrace, Error> { ) -> Result<impl LayoutMaybeTrace, Error> {
let notification = notification.map(|w| (w, notification_level)); let notification = notification.map(|w| (w, notification_level));
let layout = RootComponent::new(Homescreen::new(label, notification, hold)?); let layout = RootComponent::new(Homescreen::new(label, notification, lockable)?);
Ok(layout) Ok(layout)
} }

View File

@ -1016,9 +1016,9 @@ impl FirmwareUI for UIEckhart {
fn show_homescreen( fn show_homescreen(
label: TString<'static>, label: TString<'static>,
hold: bool,
notification: Option<TString<'static>>, notification: Option<TString<'static>>,
notification_level: u8, notification_level: u8,
lockable: bool,
) -> Result<impl LayoutMaybeTrace, Error> { ) -> Result<impl LayoutMaybeTrace, Error> {
let locked = false; let locked = false;
let bootscreen = false; let bootscreen = false;
@ -1026,7 +1026,7 @@ impl FirmwareUI for UIEckhart {
let notification = notification.map(|w| (w, notification_level)); let notification = notification.map(|w| (w, notification_level));
let layout = RootComponent::new(Homescreen::new( let layout = RootComponent::new(Homescreen::new(
label, label,
hold, lockable,
locked, locked,
bootscreen, bootscreen,
coinjoin_authorized, coinjoin_authorized,

View File

@ -308,9 +308,9 @@ pub trait FirmwareUI {
fn show_homescreen( fn show_homescreen(
label: TString<'static>, label: TString<'static>,
hold: bool,
notification: Option<TString<'static>>, notification: Option<TString<'static>>,
notification_level: u8, notification_level: u8,
lockable: bool,
) -> Result<impl LayoutMaybeTrace, Error>; ) -> Result<impl LayoutMaybeTrace, Error>;
fn show_device_menu( fn show_device_menu(

View File

@ -541,9 +541,9 @@ def show_group_share_success(
def show_homescreen( def show_homescreen(
*, *,
label: str | None, label: str | None,
hold: bool,
notification: str | None, notification: str | None,
notification_level: int = 0, notification_level: int = 0,
lockable: bool,
skip_first_paint: bool, skip_first_paint: bool,
) -> LayoutObj[UiResult]: ) -> LayoutObj[UiResult]:
"""Idle homescreen.""" """Idle homescreen."""

View File

@ -31,27 +31,31 @@ async def homescreen() -> None:
# TODO: add notification that translations are out of date # TODO: add notification that translations are out of date
notification = None notification = None
notification_is_error = False notification_level = 1 # 0 = strong warning, 1 = warning, 2 = info, 3 = success
if is_set_any_session(MessageType.AuthorizeCoinJoin): if is_set_any_session(MessageType.AuthorizeCoinJoin):
notification = TR.homescreen__title_coinjoin_authorized notification = TR.homescreen__title_coinjoin_authorized
notification_level = 3
elif storage.device.is_initialized() and storage.device.no_backup(): elif storage.device.is_initialized() and storage.device.no_backup():
notification = TR.homescreen__title_seedless notification = TR.homescreen__title_seedless
notification_is_error = True notification_level = 0
elif storage.device.is_initialized() and storage.device.unfinished_backup(): elif storage.device.is_initialized() and storage.device.unfinished_backup():
notification = TR.homescreen__title_backup_failed notification = TR.homescreen__title_backup_failed
notification_is_error = True notification_level = 0
elif storage.device.is_initialized() and storage.device.needs_backup(): elif storage.device.is_initialized() and storage.device.needs_backup():
notification = TR.homescreen__title_backup_needed notification = TR.homescreen__title_backup_needed
notification_level = 1
elif storage.device.is_initialized() and not config.has_pin(): elif storage.device.is_initialized() and not config.has_pin():
notification = TR.homescreen__title_pin_not_set notification = TR.homescreen__title_pin_not_set
notification_level = 1
elif storage.device.get_experimental_features(): elif storage.device.get_experimental_features():
notification = TR.homescreen__title_experimental_mode notification = TR.homescreen__title_experimental_mode
notification_level = 2
obj = Homescreen( obj = Homescreen(
label=label, label=label,
notification=notification, notification=notification,
notification_is_error=notification_is_error, notification_level=notification_level,
hold_to_lock=config.has_pin(), lockable=config.has_pin(),
) )
try: try:
res = await obj.get_result() res = await obj.get_result()

View File

@ -67,28 +67,16 @@ class Homescreen(HomescreenBase):
self, self,
label: str | None, label: str | None,
notification: str | None, notification: str | None,
notification_is_error: bool, notification_level: int,
hold_to_lock: bool, lockable: bool,
) -> None: ) -> None:
level = 1
if notification is not None:
notification = notification.rstrip(
"!"
) # TODO handle TS5 that doesn't have it
if notification == TR.homescreen__title_coinjoin_authorized:
level = 3
elif notification == TR.homescreen__title_experimental_mode:
level = 2
elif notification_is_error:
level = 0
super().__init__( super().__init__(
layout=_retry_with_gc( layout=_retry_with_gc(
trezorui_api.show_homescreen, trezorui_api.show_homescreen,
label=label, label=label,
notification=notification, notification=notification,
notification_level=level, notification_level=notification_level,
hold=hold_to_lock, lockable=lockable,
skip_first_paint=self._should_resume(), skip_first_paint=self._should_resume(),
) )
) )