Ignore duplicate events in a much less hacky way

Immediately reduce tech debt.
This commit is contained in:
Isaiah Odhner 2023-09-09 23:42:30 -04:00
parent ea07b54315
commit 792d5c8294

View File

@ -74,18 +74,13 @@ class PilotRecorder():
self.next_after_exit: Callable[[], None] | None = None
recorder = self
hack = True
async def on_event(self: PaintApp, event: Event) -> None:
# FIXME: every event is received in duplicate
# Ignoring every other event is a really stupid way to fix it,
# but I don't know why it's happening.
nonlocal hack # "oh no remote hacking"
hack = not hack # "psh this hack isn't really a hack"
if hack:
await original_on_event(self, event)
return
# Record before the event is handled, so a clicked button that closes a dialog,
# removing the button from the DOM, will still be in the DOM when we record it.
# Don't record forwarded events, because then every action is duplicated.
# I don't know if recording only forwarded events would make more sense,
# I don't claim to understand the forwarding scheme.
if not event._forwarded:
recorder.record_event(event)
await original_on_event(self, event)
self.app_on_event = on_event