diff --git a/core/src/all_modules.py b/core/src/all_modules.py index c9f28bd33..47ab4c333 100644 --- a/core/src/all_modules.py +++ b/core/src/all_modules.py @@ -153,6 +153,8 @@ trezor.ui.layouts.fido import trezor.ui.layouts.fido trezor.ui.layouts.homescreen import trezor.ui.layouts.homescreen +trezor.ui.layouts.progress +import trezor.ui.layouts.progress trezor.ui.layouts.recovery import trezor.ui.layouts.recovery trezor.ui.layouts.reset @@ -165,6 +167,8 @@ trezor.ui.layouts.tt_v2.fido import trezor.ui.layouts.tt_v2.fido trezor.ui.layouts.tt_v2.homescreen import trezor.ui.layouts.tt_v2.homescreen +trezor.ui.layouts.tt_v2.progress +import trezor.ui.layouts.tt_v2.progress trezor.ui.layouts.tt_v2.recovery import trezor.ui.layouts.tt_v2.recovery trezor.ui.layouts.tt_v2.reset diff --git a/core/src/apps/bitcoin/sign_tx/progress.py b/core/src/apps/bitcoin/sign_tx/progress.py index 8e150ce59..32697e138 100644 --- a/core/src/apps/bitcoin/sign_tx/progress.py +++ b/core/src/apps/bitcoin/sign_tx/progress.py @@ -111,7 +111,7 @@ class Progress: def report_init(self) -> None: from trezor import workflow - from trezor.ui.layouts import bitcoin_progress, coinjoin_progress + from trezor.ui.layouts.progress import bitcoin_progress, coinjoin_progress progress_layout = bitcoin_progress if self.is_coinjoin: diff --git a/core/src/apps/common/mnemonic.py b/core/src/apps/common/mnemonic.py index 056da8e19..9e6c03781 100644 --- a/core/src/apps/common/mnemonic.py +++ b/core/src/apps/common/mnemonic.py @@ -97,7 +97,7 @@ _progress_obj: ProgressLayout | None = None def _start_progress() -> None: from trezor import workflow - from trezor.ui.layouts import progress + from trezor.ui.layouts.progress import progress global _progress_obj diff --git a/core/src/apps/misc/get_firmware_hash.py b/core/src/apps/misc/get_firmware_hash.py index 2eac1a463..278c91db8 100644 --- a/core/src/apps/misc/get_firmware_hash.py +++ b/core/src/apps/misc/get_firmware_hash.py @@ -11,7 +11,7 @@ _progress_obj: ProgressLayout | None = None async def get_firmware_hash(ctx: Context, msg: GetFirmwareHash) -> FirmwareHash: from trezor.messages import FirmwareHash from trezor.utils import firmware_hash - from trezor.ui.layouts import progress + from trezor.ui.layouts.progress import progress from trezor import wire, workflow workflow.close_others() diff --git a/core/src/apps/monero/layout.py b/core/src/apps/monero/layout.py index 00d1107ea..355f88876 100644 --- a/core/src/apps/monero/layout.py +++ b/core/src/apps/monero/layout.py @@ -1,9 +1,8 @@ from typing import TYPE_CHECKING from trezor.enums import ButtonRequestType -from trezor.ui.layouts import ( # noqa: F401 - confirm_action, - confirm_metadata, +from trezor.ui.layouts import confirm_action, confirm_metadata # noqa: F401 +from trezor.ui.layouts.progress import ( # noqa: F401 monero_keyimage_sync_progress, monero_live_refresh_progress, monero_transaction_progress_inner, diff --git a/core/src/trezor/pin.py b/core/src/trezor/pin.py index 983533c25..f3023ff1a 100644 --- a/core/src/trezor/pin.py +++ b/core/src/trezor/pin.py @@ -25,7 +25,7 @@ def allow_all_loader_messages() -> None: def render_empty_loader(message: str, description: str) -> None: """Render empty loader to prevent the screen appear to be frozen.""" - from trezor.ui.layouts import pin_progress + from trezor.ui.layouts.progress import pin_progress global _progress_layout global _started_with_empty_loader @@ -37,7 +37,7 @@ def render_empty_loader(message: str, description: str) -> None: def show_pin_timeout(seconds: int, progress: int, message: str) -> bool: - from trezor.ui.layouts import pin_progress + from trezor.ui.layouts.progress import pin_progress # Possibility to ignore certain messages - not showing loader for them if message in _ignore_loader_messages: diff --git a/core/src/trezor/ui/layouts/progress.py b/core/src/trezor/ui/layouts/progress.py new file mode 100644 index 000000000..f61db8b56 --- /dev/null +++ b/core/src/trezor/ui/layouts/progress.py @@ -0,0 +1 @@ +from .tt_v2.progress import * # noqa: F401,F403 diff --git a/core/src/trezor/ui/layouts/tt_v2/__init__.py b/core/src/trezor/ui/layouts/tt_v2/__init__.py index 9136099e4..7c02f9263 100644 --- a/core/src/trezor/ui/layouts/tt_v2/__init__.py +++ b/core/src/trezor/ui/layouts/tt_v2/__init__.py @@ -12,7 +12,7 @@ if TYPE_CHECKING: from typing import Any, Awaitable, Iterable, NoReturn, Sequence, TypeVar from trezor.wire import GenericContext, Context - from ..common import PropertyType, ExceptionType, ProgressLayout + from ..common import PropertyType, ExceptionType T = TypeVar("T") @@ -1256,65 +1256,3 @@ async def confirm_set_new_pin( description="\n\n".join(information), br_code=br_code, ) - - -class RustProgress: - def __init__( - self, - layout: Any, - ): - self.layout = layout - ui.backlight_fade(ui.style.BACKLIGHT_DIM) - ui.display.clear() - self.layout.attach_timer_fn(self.set_timer) - self.layout.paint() - ui.backlight_fade(ui.style.BACKLIGHT_NORMAL) - - def set_timer(self, token: int, deadline: int) -> None: - raise RuntimeError # progress layouts should not set timers - - def report(self, value: int, description: str | None = None): - msg = self.layout.progress_event(value, description or "") - assert msg is None - self.layout.paint() - ui.refresh() - - -def progress( - message: str = "PLEASE WAIT", - description: str | None = None, - indeterminate: bool = False, -) -> ProgressLayout: - return RustProgress( - layout=trezorui2.show_progress( - title=message.upper(), - indeterminate=indeterminate, - description=description or "", - ) - ) - - -def bitcoin_progress(message: str) -> ProgressLayout: - return progress(message) - - -def coinjoin_progress(message: str) -> ProgressLayout: - return RustProgress( - layout=trezorui2.show_progress_coinjoin(title=message, indeterminate=False) - ) - - -def pin_progress(message: str, description: str) -> ProgressLayout: - return progress(message, description=description) - - -def monero_keyimage_sync_progress() -> ProgressLayout: - return progress("SYNCING") - - -def monero_live_refresh_progress() -> ProgressLayout: - return progress("REFRESHING", indeterminate=True) - - -def monero_transaction_progress_inner() -> ProgressLayout: - return progress("SIGNING TRANSACTION") diff --git a/core/src/trezor/ui/layouts/tt_v2/progress.py b/core/src/trezor/ui/layouts/tt_v2/progress.py new file mode 100644 index 000000000..22926dea3 --- /dev/null +++ b/core/src/trezor/ui/layouts/tt_v2/progress.py @@ -0,0 +1,72 @@ +from typing import TYPE_CHECKING + +from trezor import ui + +import trezorui2 + +if TYPE_CHECKING: + from typing import Any + + from ..common import ProgressLayout + + +class RustProgress: + def __init__( + self, + layout: Any, + ): + self.layout = layout + ui.backlight_fade(ui.style.BACKLIGHT_DIM) + ui.display.clear() + self.layout.attach_timer_fn(self.set_timer) + self.layout.paint() + ui.backlight_fade(ui.style.BACKLIGHT_NORMAL) + + def set_timer(self, token: int, deadline: int) -> None: + raise RuntimeError # progress layouts should not set timers + + def report(self, value: int, description: str | None = None): + msg = self.layout.progress_event(value, description or "") + assert msg is None + self.layout.paint() + ui.refresh() + + +def progress( + message: str = "PLEASE WAIT", + description: str | None = None, + indeterminate: bool = False, +) -> ProgressLayout: + return RustProgress( + layout=trezorui2.show_progress( + title=message.upper(), + indeterminate=indeterminate, + description=description or "", + ) + ) + + +def bitcoin_progress(message: str) -> ProgressLayout: + return progress(message) + + +def coinjoin_progress(message: str) -> ProgressLayout: + return RustProgress( + layout=trezorui2.show_progress_coinjoin(title=message, indeterminate=False) + ) + + +def pin_progress(message: str, description: str) -> ProgressLayout: + return progress(message, description=description) + + +def monero_keyimage_sync_progress() -> ProgressLayout: + return progress("SYNCING") + + +def monero_live_refresh_progress() -> ProgressLayout: + return progress("REFRESHING", indeterminate=True) + + +def monero_transaction_progress_inner() -> ProgressLayout: + return progress("SIGNING TRANSACTION")