mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-18 05:28:40 +00:00
core: make sure that auto-lock shuts down running workflows
This commit is contained in:
parent
2d0206c043
commit
42e7c43c7c
@ -103,7 +103,6 @@ async def handle_Cancel(ctx: wire.Context, msg: Cancel) -> NoReturn:
|
|||||||
|
|
||||||
async def handle_LockDevice(ctx: wire.Context, msg: LockDevice) -> Success:
|
async def handle_LockDevice(ctx: wire.Context, msg: LockDevice) -> Success:
|
||||||
lock_device()
|
lock_device()
|
||||||
workflow.kill_default() # this restarts the homescreen to show lock icon
|
|
||||||
return Success()
|
return Success()
|
||||||
|
|
||||||
|
|
||||||
@ -145,8 +144,9 @@ def set_homescreen() -> None:
|
|||||||
def lock_device() -> None:
|
def lock_device() -> None:
|
||||||
if config.has_pin():
|
if config.has_pin():
|
||||||
config.lock()
|
config.lock()
|
||||||
set_homescreen()
|
|
||||||
wire.find_handler = get_pinlocked_handler
|
wire.find_handler = get_pinlocked_handler
|
||||||
|
set_homescreen()
|
||||||
|
workflow.close_others()
|
||||||
|
|
||||||
|
|
||||||
async def unlock_device(ctx: wire.GenericContext = wire.DUMMY_CONTEXT) -> None:
|
async def unlock_device(ctx: wire.GenericContext = wire.DUMMY_CONTEXT) -> None:
|
||||||
|
@ -113,6 +113,24 @@ def kill_default() -> None:
|
|||||||
loop.close(default_task)
|
loop.close(default_task)
|
||||||
|
|
||||||
|
|
||||||
|
def close_others() -> None:
|
||||||
|
"""Shut down all running tasks, except the one that is currently executing, and
|
||||||
|
restart the default."""
|
||||||
|
try:
|
||||||
|
kill_default()
|
||||||
|
# if no other tasks are running, start_default will run immediately
|
||||||
|
except ValueError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
# we need a local copy of tasks because processing task.close() modifies
|
||||||
|
# the global instance
|
||||||
|
for task in list(tasks):
|
||||||
|
if not task.is_running():
|
||||||
|
task.close()
|
||||||
|
|
||||||
|
# if tasks were running, closing the last of them will run start_default
|
||||||
|
|
||||||
|
|
||||||
def _finalize_default(task: loop.Task, value: Any) -> None:
|
def _finalize_default(task: loop.Task, value: Any) -> None:
|
||||||
"""Finalizer for the default task. Cleans up globals and restarts the default
|
"""Finalizer for the default task. Cleans up globals and restarts the default
|
||||||
in case no other task is running."""
|
in case no other task is running."""
|
||||||
|
Loading…
Reference in New Issue
Block a user