mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-01-03 20:11:00 +00:00
fix(core): properly send the resume signal to homescreen layouts
This commit is contained in:
parent
8a2a381949
commit
313e9e5c48
@ -8,12 +8,12 @@ import trezorui2
|
||||
from trezor import io, log, loop, utils, wire, workflow
|
||||
from trezor.messages import ButtonAck, ButtonRequest
|
||||
from trezor.wire import context
|
||||
from trezorui2 import BacklightLevels, LayoutState
|
||||
from trezorui2 import AttachType, BacklightLevels, LayoutState
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from typing import Any, Callable, Generator, Generic, Iterator, TypeVar
|
||||
|
||||
from trezorui2 import AttachType, LayoutObj, UiResult # noqa: F401
|
||||
from trezorui2 import LayoutObj, UiResult # noqa: F401
|
||||
|
||||
T = TypeVar("T", covariant=True)
|
||||
|
||||
@ -169,6 +169,10 @@ class Layout(Generic[T]):
|
||||
self.context: context.Context | None = None
|
||||
self.state: LayoutState = LayoutState.INITIAL
|
||||
|
||||
# Indicates whether we should use Resume attach style when launching.
|
||||
# Homescreen layouts can override this.
|
||||
self.should_resume = False
|
||||
|
||||
def is_ready(self) -> bool:
|
||||
"""True if the layout is in READY state."""
|
||||
return CURRENT_LAYOUT is not self and self.result_box.is_empty()
|
||||
@ -198,7 +202,7 @@ class Layout(Generic[T]):
|
||||
# make sure we are not restarted before picking the previous result
|
||||
assert self.is_ready()
|
||||
|
||||
transition_in = None
|
||||
transition_in = AttachType.RESUME if self.should_resume else AttachType.INITIAL
|
||||
|
||||
# set up the global layout, shutting down any competitors
|
||||
# (caller should still call `workflow.close_others()` to ensure that someone
|
||||
|
@ -1,7 +1,7 @@
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
import trezorui2
|
||||
from trezor import ui, utils, workflow
|
||||
from trezor import ui, workflow
|
||||
from trezor.enums import ButtonRequestType
|
||||
from trezor.messages import ButtonAck, ButtonRequest
|
||||
from trezor.wire import ActionCancelled, context
|
||||
@ -109,14 +109,4 @@ async def with_info(
|
||||
|
||||
|
||||
def draw_simple(layout: trezorui2.LayoutObj[Any]) -> None:
|
||||
# Simple drawing not supported for layouts that set timers.
|
||||
def dummy_set_timer(token: int, duration: int) -> None:
|
||||
raise RuntimeError
|
||||
|
||||
layout.attach_timer_fn(dummy_set_timer, None)
|
||||
if utils.USE_BACKLIGHT:
|
||||
ui.backlight_fade(ui.BacklightLevels.DIM)
|
||||
if layout.paint():
|
||||
ui.refresh()
|
||||
if utils.USE_BACKLIGHT:
|
||||
ui.backlight_fade(ui.BacklightLevels.NORMAL)
|
||||
ui.Layout(layout).start()
|
||||
|
@ -15,13 +15,17 @@ class HomescreenBase(ui.Layout):
|
||||
|
||||
def __init__(self, layout: Any) -> None:
|
||||
super().__init__(layout=layout)
|
||||
self.should_resume = self._should_resume()
|
||||
|
||||
def _should_resume(self) -> bool:
|
||||
return storage_cache.homescreen_shown is self.RENDER_INDICATOR
|
||||
|
||||
def _paint(self) -> None:
|
||||
if self.layout.paint():
|
||||
ui.refresh()
|
||||
|
||||
def _first_paint(self) -> None:
|
||||
if storage_cache.homescreen_shown is not self.RENDER_INDICATOR:
|
||||
if not self.should_resume:
|
||||
super()._first_paint()
|
||||
storage_cache.homescreen_shown = self.RENDER_INDICATOR
|
||||
# else:
|
||||
@ -50,15 +54,14 @@ class Homescreen(HomescreenBase):
|
||||
elif notification_is_error:
|
||||
level = 0
|
||||
|
||||
skip = storage_cache.homescreen_shown is self.RENDER_INDICATOR
|
||||
super().__init__(
|
||||
layout=trezorui2.show_homescreen(
|
||||
label=label,
|
||||
notification=notification,
|
||||
notification_level=level,
|
||||
hold=hold_to_lock,
|
||||
skip_first_paint=skip,
|
||||
),
|
||||
skip_first_paint=self._should_resume(),
|
||||
)
|
||||
)
|
||||
|
||||
async def usb_checker_task(self) -> None:
|
||||
@ -99,6 +102,7 @@ class Lockscreen(HomescreenBase):
|
||||
coinjoin_authorized=coinjoin_authorized,
|
||||
),
|
||||
)
|
||||
self.should_resume = skip
|
||||
|
||||
async def get_result(self) -> Any:
|
||||
result = await super().get_result()
|
||||
@ -111,13 +115,12 @@ class Busyscreen(HomescreenBase):
|
||||
RENDER_INDICATOR = storage_cache.BUSYSCREEN_ON
|
||||
|
||||
def __init__(self, delay_ms: int) -> None:
|
||||
skip = storage_cache.homescreen_shown is self.RENDER_INDICATOR
|
||||
super().__init__(
|
||||
layout=trezorui2.show_progress_coinjoin(
|
||||
title=TR.coinjoin__waiting_for_others,
|
||||
indeterminate=True,
|
||||
time_ms=delay_ms,
|
||||
skip_first_paint=skip,
|
||||
skip_first_paint=self._should_resume(),
|
||||
)
|
||||
)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user