mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-07-18 12:38:37 +00:00
chore(eckhart): improve DeviceMenu
- show BackupFailed correctly based on storage conditions - separate autolock duration formatting to a separate function in `trezor/strings.py`
This commit is contained in:
parent
d73f0dc79d
commit
10e88c870e
@ -30,36 +30,18 @@ async def _prompt_auto_lock_delay() -> int:
|
|||||||
async def handle_device_menu() -> None:
|
async def handle_device_menu() -> None:
|
||||||
from trezor import strings
|
from trezor import strings
|
||||||
|
|
||||||
|
# TODO: unify with notification handling in `apps/homescreen/__init__.py:homescreen()`
|
||||||
|
failed_backup = (
|
||||||
|
storage.device.is_initialized() and storage.device.unfinished_backup()
|
||||||
|
)
|
||||||
# MOCK DATA
|
# MOCK DATA
|
||||||
failed_backup = True
|
|
||||||
battery_percentage = 22
|
battery_percentage = 22
|
||||||
paired_devices = ["Trezor Suite"]
|
paired_devices = ["Trezor Suite"]
|
||||||
# ###
|
# ###
|
||||||
firmware_version = ".".join(map(str, utils.VERSION))
|
firmware_version = ".".join(map(str, utils.VERSION))
|
||||||
device_name = storage.device.get_label() or "Trezor"
|
device_name = storage.device.get_label() or "Trezor"
|
||||||
# Determine appropriate unit and count for auto-lock delay
|
|
||||||
auto_lock_ms = storage.device.get_autolock_delay_ms()
|
auto_lock_ms = storage.device.get_autolock_delay_ms()
|
||||||
MS = 1000
|
auto_lock_delay = strings.format_autolock_duration(auto_lock_ms)
|
||||||
MIN = MS * 60
|
|
||||||
HOUR = MIN * 60
|
|
||||||
DAY = HOUR * 24
|
|
||||||
|
|
||||||
if auto_lock_ms >= DAY:
|
|
||||||
auto_lock_num = auto_lock_ms // DAY
|
|
||||||
auto_lock_label = TR.plurals__lock_after_x_days
|
|
||||||
elif auto_lock_ms >= HOUR:
|
|
||||||
auto_lock_num = auto_lock_ms // HOUR
|
|
||||||
auto_lock_label = TR.plurals__lock_after_x_hours
|
|
||||||
elif auto_lock_ms >= MIN:
|
|
||||||
auto_lock_num = auto_lock_ms // MIN
|
|
||||||
auto_lock_label = TR.plurals__lock_after_x_minutes
|
|
||||||
else:
|
|
||||||
auto_lock_num = auto_lock_ms // MS
|
|
||||||
auto_lock_label = TR.plurals__lock_after_x_seconds
|
|
||||||
|
|
||||||
auto_lock_str = strings.format_plural(
|
|
||||||
"{count} {plural}", auto_lock_num, auto_lock_label
|
|
||||||
)
|
|
||||||
|
|
||||||
menu_result = await interact(
|
menu_result = await interact(
|
||||||
trezorui_api.show_device_menu(
|
trezorui_api.show_device_menu(
|
||||||
@ -68,7 +50,7 @@ async def handle_device_menu() -> None:
|
|||||||
paired_devices=paired_devices,
|
paired_devices=paired_devices,
|
||||||
firmware_version=firmware_version,
|
firmware_version=firmware_version,
|
||||||
device_name=device_name,
|
device_name=device_name,
|
||||||
auto_lock_delay=auto_lock_str,
|
auto_lock_delay=auto_lock_delay,
|
||||||
),
|
),
|
||||||
"device_menu",
|
"device_menu",
|
||||||
)
|
)
|
||||||
|
@ -119,3 +119,30 @@ def format_timestamp(timestamp: int) -> str:
|
|||||||
# that is used internally.
|
# that is used internally.
|
||||||
d = utime.gmtime2000(timestamp - _SECONDS_1970_TO_2000)
|
d = utime.gmtime2000(timestamp - _SECONDS_1970_TO_2000)
|
||||||
return f"{d[0]}-{d[1]:02d}-{d[2]:02d} {d[3]:02d}:{d[4]:02d}:{d[5]:02d}"
|
return f"{d[0]}-{d[1]:02d}-{d[2]:02d} {d[3]:02d}:{d[4]:02d}:{d[5]:02d}"
|
||||||
|
|
||||||
|
|
||||||
|
def format_autolock_duration(auto_lock_ms: int) -> str:
|
||||||
|
"""
|
||||||
|
Determine appropriate unit and count for auto-lock delay.
|
||||||
|
"""
|
||||||
|
from . import TR
|
||||||
|
|
||||||
|
MS = 1000
|
||||||
|
MIN = MS * 60
|
||||||
|
HOUR = MIN * 60
|
||||||
|
DAY = HOUR * 24
|
||||||
|
|
||||||
|
if auto_lock_ms >= DAY:
|
||||||
|
auto_lock_num = auto_lock_ms // DAY
|
||||||
|
auto_lock_label = TR.plurals__lock_after_x_days
|
||||||
|
elif auto_lock_ms >= HOUR:
|
||||||
|
auto_lock_num = auto_lock_ms // HOUR
|
||||||
|
auto_lock_label = TR.plurals__lock_after_x_hours
|
||||||
|
elif auto_lock_ms >= MIN:
|
||||||
|
auto_lock_num = auto_lock_ms // MIN
|
||||||
|
auto_lock_label = TR.plurals__lock_after_x_minutes
|
||||||
|
else:
|
||||||
|
auto_lock_num = auto_lock_ms // MS
|
||||||
|
auto_lock_label = TR.plurals__lock_after_x_seconds
|
||||||
|
|
||||||
|
return format_plural("{count} {plural}", auto_lock_num, auto_lock_label)
|
||||||
|
Loading…
Reference in New Issue
Block a user