mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-23 06:48:16 +00:00
chore(core): decrease homescreen size by 280 bytes
This commit is contained in:
parent
11fc2d36f7
commit
48b4c5aaba
@ -2,7 +2,7 @@ from typing import Any
|
|||||||
|
|
||||||
import storage.cache
|
import storage.cache
|
||||||
import storage.device
|
import storage.device
|
||||||
from trezor import res, ui
|
from trezor import ui
|
||||||
|
|
||||||
|
|
||||||
class HomescreenBase(ui.Layout):
|
class HomescreenBase(ui.Layout):
|
||||||
@ -14,6 +14,8 @@ class HomescreenBase(ui.Layout):
|
|||||||
self.repaint = storage.cache.homescreen_shown is not self.RENDER_INDICATOR
|
self.repaint = storage.cache.homescreen_shown is not self.RENDER_INDICATOR
|
||||||
|
|
||||||
def get_image(self) -> bytes:
|
def get_image(self) -> bytes:
|
||||||
|
from trezor import res
|
||||||
|
|
||||||
return storage.device.get_homescreen() or res.load(
|
return storage.device.get_homescreen() or res.load(
|
||||||
"apps/homescreen/res/bg.toif"
|
"apps/homescreen/res/bg.toif"
|
||||||
)
|
)
|
||||||
|
@ -1,27 +1,33 @@
|
|||||||
import storage.cache
|
from typing import TYPE_CHECKING
|
||||||
from trezor import loop, ui
|
|
||||||
from trezor.ui.layouts import show_coinjoin
|
|
||||||
|
|
||||||
from apps.base import busy_expiry_ms, set_homescreen
|
import storage.cache as storage_cache
|
||||||
|
|
||||||
from . import HomescreenBase
|
from . import HomescreenBase
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from trezor import loop
|
||||||
|
|
||||||
|
|
||||||
async def busyscreen() -> None:
|
async def busyscreen() -> None:
|
||||||
await Busyscreen()
|
await Busyscreen()
|
||||||
|
|
||||||
|
|
||||||
class Busyscreen(HomescreenBase):
|
class Busyscreen(HomescreenBase):
|
||||||
RENDER_INDICATOR = storage.cache.BUSYSCREEN_ON
|
RENDER_INDICATOR = storage_cache.BUSYSCREEN_ON
|
||||||
|
|
||||||
def create_tasks(self) -> tuple[loop.AwaitableTask, ...]:
|
def create_tasks(self) -> tuple[loop.AwaitableTask, ...]:
|
||||||
return self.handle_rendering(), self.handle_input(), self.handle_expiry()
|
return self.handle_rendering(), self.handle_input(), self.handle_expiry()
|
||||||
|
|
||||||
def handle_expiry(self) -> loop.Task: # type: ignore [awaitable-is-generator]
|
def handle_expiry(self) -> loop.Task: # type: ignore [awaitable-is-generator]
|
||||||
|
from apps.base import busy_expiry_ms, set_homescreen
|
||||||
|
from trezor import ui, loop
|
||||||
|
|
||||||
yield loop.sleep(busy_expiry_ms())
|
yield loop.sleep(busy_expiry_ms())
|
||||||
storage.cache.delete(storage.cache.APP_COMMON_BUSY_DEADLINE_MS)
|
storage_cache.delete(storage_cache.APP_COMMON_BUSY_DEADLINE_MS)
|
||||||
set_homescreen()
|
set_homescreen()
|
||||||
raise ui.Result(None)
|
raise ui.Result(None)
|
||||||
|
|
||||||
def do_render(self) -> None:
|
def do_render(self) -> None:
|
||||||
|
from trezor.ui.layouts import show_coinjoin
|
||||||
|
|
||||||
show_coinjoin()
|
show_coinjoin()
|
||||||
|
@ -1,22 +1,23 @@
|
|||||||
import utime
|
import utime
|
||||||
from micropython import const
|
from micropython import const
|
||||||
from typing import Tuple
|
from typing import TYPE_CHECKING, Tuple
|
||||||
|
|
||||||
import storage
|
|
||||||
import storage.cache
|
import storage.cache
|
||||||
import storage.device
|
from trezor import config, ui
|
||||||
from trezor import config, io, loop, ui, utils
|
|
||||||
from trezor.ui.loader import Loader, LoaderNeutral
|
|
||||||
|
|
||||||
from apps.base import lock_device
|
|
||||||
|
|
||||||
from . import HomescreenBase
|
from . import HomescreenBase
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from trezor import loop
|
||||||
|
|
||||||
|
|
||||||
_LOADER_DELAY_MS = const(500)
|
_LOADER_DELAY_MS = const(500)
|
||||||
_LOADER_TOTAL_MS = const(2500)
|
_LOADER_TOTAL_MS = const(2500)
|
||||||
|
|
||||||
|
|
||||||
async def homescreen() -> None:
|
async def homescreen() -> None:
|
||||||
|
from apps.base import lock_device
|
||||||
|
|
||||||
await Homescreen()
|
await Homescreen()
|
||||||
lock_device()
|
lock_device()
|
||||||
|
|
||||||
@ -25,15 +26,18 @@ class Homescreen(HomescreenBase):
|
|||||||
RENDER_INDICATOR = storage.cache.HOMESCREEN_ON
|
RENDER_INDICATOR = storage.cache.HOMESCREEN_ON
|
||||||
|
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
|
from trezor.ui.loader import Loader, LoaderNeutral
|
||||||
|
import storage.device as storage_device
|
||||||
|
|
||||||
super().__init__()
|
super().__init__()
|
||||||
if not storage.device.is_initialized():
|
if not storage_device.is_initialized():
|
||||||
self.label = "Go to trezor.io/start"
|
self.label = "Go to trezor.io/start"
|
||||||
|
|
||||||
self.loader = Loader(
|
self.loader = Loader(
|
||||||
style=LoaderNeutral,
|
LoaderNeutral,
|
||||||
target_ms=_LOADER_TOTAL_MS - _LOADER_DELAY_MS,
|
_LOADER_TOTAL_MS - _LOADER_DELAY_MS,
|
||||||
offset_y=-10,
|
-10,
|
||||||
reverse_speedup=3,
|
3,
|
||||||
)
|
)
|
||||||
self.touch_ms: int | None = None
|
self.touch_ms: int | None = None
|
||||||
|
|
||||||
@ -41,45 +45,61 @@ class Homescreen(HomescreenBase):
|
|||||||
return super().create_tasks() + (self.usb_checker_task(),)
|
return super().create_tasks() + (self.usb_checker_task(),)
|
||||||
|
|
||||||
async def usb_checker_task(self) -> None:
|
async def usb_checker_task(self) -> None:
|
||||||
|
from trezor import loop, io
|
||||||
|
|
||||||
usbcheck = loop.wait(io.USB_CHECK)
|
usbcheck = loop.wait(io.USB_CHECK)
|
||||||
while True:
|
while True:
|
||||||
await usbcheck
|
await usbcheck
|
||||||
self.set_repaint(True)
|
self.set_repaint(True)
|
||||||
|
|
||||||
def do_render(self) -> None:
|
def do_render(self) -> None:
|
||||||
|
from trezor import utils
|
||||||
|
from trezor import ui # local_cache_global
|
||||||
|
import storage.device as storage_device
|
||||||
|
|
||||||
|
header_error = ui.header_error # local_cache_attribute
|
||||||
|
header_warning = ui.header_warning # local_cache_attribute
|
||||||
|
display = ui.display # local_cache_attribute
|
||||||
|
model = utils.MODEL # local_cache_attribute
|
||||||
|
|
||||||
# warning bar on top
|
# warning bar on top
|
||||||
if storage.device.is_initialized() and storage.device.no_backup():
|
if storage_device.is_initialized() and storage_device.no_backup():
|
||||||
ui.header_error("SEEDLESS")
|
header_error("SEEDLESS")
|
||||||
elif storage.device.is_initialized() and storage.device.unfinished_backup():
|
elif storage_device.is_initialized() and storage_device.unfinished_backup():
|
||||||
ui.header_error("BACKUP FAILED!")
|
header_error("BACKUP FAILED!")
|
||||||
elif storage.device.is_initialized() and storage.device.needs_backup():
|
elif storage_device.is_initialized() and storage_device.needs_backup():
|
||||||
ui.header_warning("NEEDS BACKUP!")
|
header_warning("NEEDS BACKUP!")
|
||||||
elif storage.device.is_initialized() and not config.has_pin():
|
elif storage_device.is_initialized() and not config.has_pin():
|
||||||
ui.header_warning("PIN NOT SET!")
|
header_warning("PIN NOT SET!")
|
||||||
elif storage.device.get_experimental_features():
|
elif storage_device.get_experimental_features():
|
||||||
ui.header_warning("EXPERIMENTAL MODE!")
|
header_warning("EXPERIMENTAL MODE!")
|
||||||
else:
|
else:
|
||||||
ui.display.bar(0, 0, ui.WIDTH, ui.get_header_height(), ui.BG)
|
display.bar(0, 0, ui.WIDTH, ui.get_header_height(), ui.BG)
|
||||||
|
|
||||||
# homescreen with shifted avatar and text on bottom
|
# homescreen with shifted avatar and text on bottom
|
||||||
# Differs for each model
|
# Differs for each model
|
||||||
|
|
||||||
if not utils.usb_data_connected():
|
if not utils.usb_data_connected():
|
||||||
ui.header_error("NO USB CONNECTION")
|
header_error("NO USB CONNECTION")
|
||||||
|
|
||||||
# TODO: support homescreen avatar change for R and 1
|
# TODO: support homescreen avatar change for R and 1
|
||||||
if utils.MODEL in ("T",):
|
if model in ("T",):
|
||||||
ui.display.avatar(48, 48 - 10, self.get_image(), ui.WHITE, ui.BLACK)
|
display.avatar(48, 48 - 10, self.get_image(), ui.WHITE, ui.BLACK)
|
||||||
elif utils.MODEL in ("R",):
|
elif model in ("R",):
|
||||||
icon = "trezor/res/homescreen_model_r.toif" # 92x92 px
|
icon = "trezor/res/homescreen_model_r.toif" # 92x92 px
|
||||||
ui.display.icon(18, 18, ui.res.load(icon), ui.style.FG, ui.style.BG)
|
display.icon(18, 18, ui.res.load(icon), ui.style.FG, ui.style.BG)
|
||||||
elif utils.MODEL in ("1",):
|
elif model in ("1",):
|
||||||
icon = "trezor/res/homescreen_model_1.toif" # 64x36 px
|
icon = "trezor/res/homescreen_model_1.toif" # 64x36 px
|
||||||
ui.display.icon(33, 14, ui.res.load(icon), ui.style.FG, ui.style.BG)
|
display.icon(33, 14, ui.res.load(icon), ui.style.FG, ui.style.BG)
|
||||||
|
|
||||||
label_heights = {"1": 60, "R": 120, "T": 220}
|
label_heights = {"1": 60, "R": 120, "T": 220}
|
||||||
ui.display.text_center(
|
display.text_center(
|
||||||
ui.WIDTH // 2, label_heights[utils.MODEL], self.label, ui.BOLD, ui.FG, ui.BG
|
ui.WIDTH // 2,
|
||||||
|
label_heights[model],
|
||||||
|
self.label,
|
||||||
|
ui.BOLD,
|
||||||
|
ui.FG,
|
||||||
|
ui.BG,
|
||||||
)
|
)
|
||||||
|
|
||||||
ui.refresh()
|
ui.refresh()
|
||||||
@ -101,18 +121,20 @@ class Homescreen(HomescreenBase):
|
|||||||
if self.loader.elapsed_ms() >= self.loader.target_ms:
|
if self.loader.elapsed_ms() >= self.loader.target_ms:
|
||||||
raise ui.Result(None)
|
raise ui.Result(None)
|
||||||
|
|
||||||
def _loader_start(self) -> None:
|
|
||||||
ui.display.clear()
|
|
||||||
ui.display.text_center(ui.WIDTH // 2, 35, "Hold to lock", ui.BOLD, ui.FG, ui.BG)
|
|
||||||
self.loader.start()
|
|
||||||
|
|
||||||
def dispatch(self, event: int, x: int, y: int) -> None:
|
def dispatch(self, event: int, x: int, y: int) -> None:
|
||||||
if (
|
if (
|
||||||
self.touch_ms is not None
|
self.touch_ms is not None
|
||||||
and self.touch_ms + _LOADER_DELAY_MS < utime.ticks_ms()
|
and self.touch_ms + _LOADER_DELAY_MS < utime.ticks_ms()
|
||||||
):
|
):
|
||||||
self.touch_ms = None
|
self.touch_ms = None
|
||||||
self._loader_start()
|
|
||||||
|
# _loader_start
|
||||||
|
ui.display.clear()
|
||||||
|
ui.display.text_center(
|
||||||
|
ui.WIDTH // 2, 35, "Hold to lock", ui.BOLD, ui.FG, ui.BG
|
||||||
|
)
|
||||||
|
self.loader.start()
|
||||||
|
# END _loader_start
|
||||||
|
|
||||||
if event is ui.RENDER and self.loader.start_ms is not None:
|
if event is ui.RENDER and self.loader.start_ms is not None:
|
||||||
self.loader.dispatch(event, x, y)
|
self.loader.dispatch(event, x, y)
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
import storage.cache
|
import storage.cache
|
||||||
from trezor import loop, res, ui, wire
|
from trezor import loop, ui
|
||||||
|
|
||||||
from . import HomescreenBase
|
from . import HomescreenBase
|
||||||
|
|
||||||
|
|
||||||
async def lockscreen() -> None:
|
async def lockscreen() -> None:
|
||||||
|
from trezor import wire
|
||||||
|
|
||||||
from apps.common.request_pin import can_lock_device
|
from apps.common.request_pin import can_lock_device
|
||||||
from apps.base import unlock_device
|
from apps.base import unlock_device
|
||||||
|
|
||||||
@ -37,24 +39,29 @@ class Lockscreen(HomescreenBase):
|
|||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
def do_render(self) -> None:
|
def do_render(self) -> None:
|
||||||
|
from trezor import res
|
||||||
|
from trezor import ui # local_cache_global
|
||||||
|
|
||||||
|
display = ui.display # local_cache_attribute
|
||||||
|
title_grey = ui.TITLE_GREY # local_cache_attribute
|
||||||
|
bg = ui.BG # local_cache_attribute
|
||||||
|
|
||||||
# homescreen with label text on top
|
# homescreen with label text on top
|
||||||
ui.display.text_center(
|
display.text_center(ui.WIDTH // 2, 35, self.label, ui.BOLD, title_grey, bg)
|
||||||
ui.WIDTH // 2, 35, self.label, ui.BOLD, ui.TITLE_GREY, ui.BG
|
display.avatar(48, 48, self.get_image(), ui.WHITE, ui.BLACK)
|
||||||
)
|
|
||||||
ui.display.avatar(48, 48, self.get_image(), ui.WHITE, ui.BLACK)
|
|
||||||
|
|
||||||
# lock bar
|
# lock bar
|
||||||
ui.display.bar_radius(40, 100, 160, 40, ui.TITLE_GREY, ui.BG, 4)
|
display.bar_radius(40, 100, 160, 40, title_grey, bg, 4)
|
||||||
ui.display.bar_radius(42, 102, 156, 36, ui.BG, ui.TITLE_GREY, 4)
|
display.bar_radius(42, 102, 156, 36, bg, title_grey, 4)
|
||||||
ui.display.text_center(
|
display.text_center(
|
||||||
ui.WIDTH // 2, 128, self.lock_label, ui.BOLD, ui.TITLE_GREY, ui.BG
|
ui.WIDTH // 2, 128, self.lock_label, ui.BOLD, title_grey, bg
|
||||||
)
|
)
|
||||||
|
|
||||||
# "tap to unlock"
|
# "tap to unlock"
|
||||||
ui.display.text_center(
|
display.text_center(
|
||||||
ui.WIDTH // 2 + 10, 220, self.tap_label, ui.BOLD, ui.TITLE_GREY, ui.BG
|
ui.WIDTH // 2 + 10, 220, self.tap_label, ui.BOLD, title_grey, bg
|
||||||
)
|
)
|
||||||
ui.display.icon(45, 202, res.load(ui.ICON_CLICK), ui.TITLE_GREY, ui.BG)
|
display.icon(45, 202, res.load(ui.ICON_CLICK), title_grey, bg)
|
||||||
|
|
||||||
def on_touch_end(self, _x: int, _y: int) -> None:
|
def on_touch_end(self, _x: int, _y: int) -> None:
|
||||||
raise ui.Result(None)
|
raise ui.Result(None)
|
||||||
|
Loading…
Reference in New Issue
Block a user