2022-10-30 16:59:59 +00:00
|
|
|
from typing import TYPE_CHECKING
|
2019-08-08 14:27:49 +00:00
|
|
|
|
2022-10-30 16:59:59 +00:00
|
|
|
if TYPE_CHECKING:
|
|
|
|
from typing import Any
|
|
|
|
from trezor.ui.layouts.common import ProgressLayout
|
2018-02-05 14:13:33 +00:00
|
|
|
|
2021-03-18 09:48:50 +00:00
|
|
|
_previous_seconds: int | None = None
|
2022-10-30 16:59:59 +00:00
|
|
|
_previous_remaining: str | None = None
|
|
|
|
_progress_layout: ProgressLayout | None = None
|
2020-10-16 17:39:32 +00:00
|
|
|
keepalive_callback: Any = None
|
2019-08-08 14:27:49 +00:00
|
|
|
|
2019-04-11 10:32:37 +00:00
|
|
|
|
2019-02-22 20:53:37 +00:00
|
|
|
def show_pin_timeout(seconds: int, progress: int, message: str) -> bool:
|
2022-10-30 16:59:59 +00:00
|
|
|
from trezor.ui.layouts import pin_progress
|
2021-03-22 15:14:24 +00:00
|
|
|
|
2019-09-06 17:53:28 +00:00
|
|
|
global _previous_seconds
|
2022-10-30 16:59:59 +00:00
|
|
|
global _previous_remaining
|
|
|
|
global _progress_layout
|
2019-04-11 10:32:37 +00:00
|
|
|
|
2019-08-08 14:27:49 +00:00
|
|
|
if callable(keepalive_callback):
|
|
|
|
keepalive_callback()
|
|
|
|
|
2022-10-30 16:59:59 +00:00
|
|
|
if progress == 0 or _progress_layout is None:
|
|
|
|
_previous_seconds = None
|
2019-09-06 17:53:28 +00:00
|
|
|
|
|
|
|
if seconds != _previous_seconds:
|
|
|
|
if seconds == 0:
|
|
|
|
remaining = "Done"
|
|
|
|
elif seconds == 1:
|
|
|
|
remaining = "1 second left"
|
|
|
|
else:
|
2021-09-27 10:13:51 +00:00
|
|
|
remaining = f"{seconds} seconds left"
|
2022-10-30 16:59:59 +00:00
|
|
|
_previous_remaining = remaining
|
2019-09-06 17:53:28 +00:00
|
|
|
_previous_seconds = seconds
|
2022-10-30 16:59:59 +00:00
|
|
|
else:
|
|
|
|
remaining = _previous_remaining
|
|
|
|
|
|
|
|
if progress == 0 or _progress_layout is None:
|
|
|
|
_progress_layout = pin_progress(message, description=remaining or "")
|
|
|
|
_progress_layout.report(progress, remaining)
|
|
|
|
# drop the layout when done so trezor.ui doesn't have to remain in memory
|
|
|
|
if seconds == 0:
|
|
|
|
_progress_layout = None
|
2019-04-11 10:32:37 +00:00
|
|
|
|
2019-02-07 11:01:08 +00:00
|
|
|
return False
|