core: make sure that auto-lock shuts down running workflows

pull/971/head
matejcik 4 years ago committed by matejcik
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:
lock_device()
workflow.kill_default() # this restarts the homescreen to show lock icon
return Success()
@ -145,8 +144,9 @@ def set_homescreen() -> None:
def lock_device() -> None:
if config.has_pin():
config.lock()
set_homescreen()
wire.find_handler = get_pinlocked_handler
set_homescreen()
workflow.close_others()
async def unlock_device(ctx: wire.GenericContext = wire.DUMMY_CONTEXT) -> None:

@ -113,6 +113,24 @@ def kill_default() -> None:
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:
"""Finalizer for the default task. Cleans up globals and restarts the default
in case no other task is running."""

Loading…
Cancel
Save