From 34f722f2df402fc6edb828a73e459d92cab6d605 Mon Sep 17 00:00:00 2001 From: Jan Pochyla Date: Mon, 19 Feb 2018 20:36:12 +0100 Subject: [PATCH] boot: add lockscreen --- src/apps/homescreen/homescreen.py | 4 +-- src/boot.py | 53 +++++++++++++++++++++---------- 2 files changed, 38 insertions(+), 19 deletions(-) diff --git a/src/apps/homescreen/homescreen.py b/src/apps/homescreen/homescreen.py index a8541b0bd5..b0b789e2b5 100644 --- a/src/apps/homescreen/homescreen.py +++ b/src/apps/homescreen/homescreen.py @@ -23,8 +23,8 @@ def display_homescreen(): image = res.load('apps/homescreen/res/bg.toif') ui.display.bar(0, 0, ui.SCREEN, ui.SCREEN, ui.BG) - ui.display.avatar((ui.SCREEN - 144) // 2, (ui.SCREEN - 144) // 2 - 10, image, ui.WHITE, ui.BLACK) - ui.display.text_center(ui.SCREEN // 2, ui.SCREEN - 20, label, ui.BOLD, ui.FG, ui.BG) + ui.display.avatar(48, 48 - 10, image, ui.WHITE, ui.BLACK) + ui.display.text_center(120, 220, label, ui.BOLD, ui.FG, ui.BG) @unimport diff --git a/src/boot.py b/src/boot.py index 68e5b9c4f1..b3e2ed5847 100644 --- a/src/boot.py +++ b/src/boot.py @@ -1,28 +1,47 @@ -from trezor import config +from trezor import config, loop, res, ui from trezor.pin import pin_to_int, show_pin_timeout -from trezor import loop -from trezor import ui - from apps.common.request_pin import request_pin -async def unlock_layout(): +async def bootscreen(): while True: - if config.has_pin(): - pin = await request_pin() - else: - pin = '' - if config.unlock(pin_to_int(pin), show_pin_timeout): - return - else: - await unlock_failed() + try: + if not config.has_pin(): + config.unlock(pin_to_int(''), show_pin_timeout) + return + await lockscreen() + while True: + pin = await request_pin() + if config.unlock(pin_to_int(pin), show_pin_timeout): + return + except: + pass -async def unlock_failed(): - pass +async def lockscreen(): + from apps.common import storage + + label = storage.get_label() + image = storage.get_homescreen() + if not label: + label = 'My TREZOR' + if not image: + image = res.load('apps/homescreen/res/bg.toif') + + await ui.backlight_slide(ui.BACKLIGHT_DIM) + + ui.display.bar(0, 0, 240, 240, ui.WHITE) + ui.display.avatar(48, 48, image, ui.BLACK, ui.WHITE) + ui.display.text_center(120, 35, label, ui.BOLD, ui.BLACK, ui.WHITE) + + ui.display.text_center(130, 220, 'Tap to unlock', ui.BOLD, ui.DARK_GREY, ui.WHITE) + ui.display.icon(45, 202, res.load(ui.ICON_CLICK), ui.DARK_GREY, ui.WHITE) + + await ui.backlight_slide(ui.BACKLIGHT_NORMAL) + await ui.click() config.init() -ui.display.backlight(ui.BACKLIGHT_DIM) -loop.schedule(unlock_layout()) +ui.display.backlight(ui.BACKLIGHT_NONE) +loop.schedule(bootscreen()) loop.run()