mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-04-22 10:09:04 +00:00
refactor(core): drain the BLE event queue whenever layout is running
[no changelog]
This commit is contained in:
parent
4f2efd8dc7
commit
092c86083c
@ -381,6 +381,9 @@ class Layout(Generic[T]):
|
||||
yield self._handle_input_iface(io.BUTTON, self.layout.button_event)
|
||||
if utils.USE_TOUCH:
|
||||
yield self._handle_input_iface(io.TOUCH, self.layout.touch_event)
|
||||
if utils.USE_BLE:
|
||||
# most layouts don't care but we don't want to keep stale events in the queue
|
||||
yield self._handle_ble_events()
|
||||
|
||||
def _handle_input_iface(
|
||||
self, iface: int, event_call: Callable[..., LayoutState | None]
|
||||
@ -430,6 +433,18 @@ class Layout(Generic[T]):
|
||||
except Exception:
|
||||
raise
|
||||
|
||||
if utils.USE_BLE:
|
||||
|
||||
async def _handle_ble_events(self) -> None:
|
||||
blecheck = loop.wait(io.BLE_EVENT)
|
||||
try:
|
||||
while True:
|
||||
event = await blecheck
|
||||
log.debug(__name__, "BLE event: %s", event)
|
||||
self._event(self.layout.ble_event, *event)
|
||||
except Shutdown:
|
||||
return
|
||||
|
||||
def _task_finalizer(self, task: loop.Task, value: Any) -> None:
|
||||
if value is None:
|
||||
# all is good
|
||||
|
@ -3,7 +3,7 @@ from typing import TYPE_CHECKING
|
||||
import storage.cache as storage_cache
|
||||
import trezorui_api
|
||||
from storage.cache_common import APP_COMMON_BUSY_DEADLINE_MS
|
||||
from trezor import TR, ui, utils
|
||||
from trezor import TR, ui
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from typing import Any, Callable, Iterator, ParamSpec, TypeVar
|
||||
@ -101,21 +101,9 @@ class Homescreen(HomescreenBase):
|
||||
event = await usbcheck
|
||||
self._event(self.layout.usb_event, event)
|
||||
|
||||
if utils.USE_BLE:
|
||||
|
||||
async def ble_checker_task(self) -> None:
|
||||
from trezor import io, loop
|
||||
|
||||
blecheck = loop.wait(io.BLE_EVENT)
|
||||
while True:
|
||||
event = await blecheck
|
||||
self._event(self.layout.ble_event, *event)
|
||||
|
||||
def create_tasks(self) -> Iterator[loop.Task]:
|
||||
yield from super().create_tasks()
|
||||
yield self.usb_checker_task()
|
||||
if utils.USE_BLE:
|
||||
yield self.ble_checker_task()
|
||||
|
||||
|
||||
class Lockscreen(HomescreenBase):
|
||||
|
Loading…
Reference in New Issue
Block a user