diff --git a/src/apps/homescreen/homescreen.py b/src/apps/homescreen/homescreen.py index b514915bb0..f3d3382566 100644 --- a/src/apps/homescreen/homescreen.py +++ b/src/apps/homescreen/homescreen.py @@ -9,15 +9,7 @@ async def swipe_to_rotate(): ui.display.orientation(degrees(swipe)) -async def dim_screen(): - await loop.sleep(5 * 1000000) - await ui.backlight_slide(ui.BACKLIGHT_DIM) - while True: - await loop.sleep(10000000) - - -@ui.layout -async def display_homescreen(): +def display_homescreen(): from apps.common import storage if not storage.is_initialized(): @@ -34,10 +26,11 @@ async def display_homescreen(): 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) - await dim_screen() - @unimport async def layout_homescreen(): while True: - await loop.wait(swipe_to_rotate(), display_homescreen()) + await ui.backlight_slide(ui.BACKLIGHT_DIM) + display_homescreen() + await ui.backlight_slide(ui.BACKLIGHT_NORMAL) + await swipe_to_rotate() diff --git a/src/trezor/ui/__init__.py b/src/trezor/ui/__init__.py index e25b0257a9..8e85c242b0 100644 --- a/src/trezor/ui/__init__.py +++ b/src/trezor/ui/__init__.py @@ -9,6 +9,7 @@ from trezorui import Display from trezor import io from trezor import loop from trezor import res +from trezor import workflow display = Display() @@ -95,7 +96,7 @@ async def click() -> tuple: return pos -async def backlight_slide(val: int, delay: int=20000, step: int=1): +async def backlight_slide(val: int, delay: int=35000, step: int=20): sleep = loop.sleep(delay) current = display.backlight() for i in range(current, val, -step if current > val else step): @@ -104,17 +105,17 @@ async def backlight_slide(val: int, delay: int=20000, step: int=1): def layout(f): - delay = const(35000) # 35ms - step = const(20) - async def inner(*args, **kwargs): - await backlight_slide(BACKLIGHT_DIM, delay, step) - slide = backlight_slide(BACKLIGHT_NORMAL, delay, step) + await backlight_slide(BACKLIGHT_DIM) + slide = backlight_slide(BACKLIGHT_NORMAL) try: + layout = f(*args, **kwargs) + workflow.onlayoutstart(layout) loop.schedule(slide) - return await f(*args, **kwargs) + return await layout finally: loop.close(slide) + workflow.onlayoutclose(layout) return inner diff --git a/src/trezor/workflow.py b/src/trezor/workflow.py index b3d27667a9..53e0fc4f56 100644 --- a/src/trezor/workflow.py +++ b/src/trezor/workflow.py @@ -5,20 +5,16 @@ from trezor import ui started = [] default = None default_handler = None +layouts = [] def onstart(w): - closedefault() started.append(w) - ui.display.backlight(ui.BACKLIGHT_NORMAL) - log.debug(__name__, 'onstart: %s', w) def onclose(w): started.remove(w) - log.debug(__name__, 'onclose: %s', w) - - if not started and default_handler: + if not started and not layouts and default_handler: startdefault(default_handler) @@ -28,7 +24,6 @@ def closedefault(): if default: loop.close(default) default = None - log.debug(__name__, 'closedefault') def startdefault(handler): @@ -39,5 +34,12 @@ def startdefault(handler): default_handler = handler default = handler() loop.schedule(default) - ui.display.backlight(ui.BACKLIGHT_NORMAL) - log.debug(__name__, 'startdefault') + + +def onlayoutstart(l): + closedefault() + layouts.append(l) + + +def onlayoutclose(l): + layouts.remove(l)