diff --git a/pylib/anki/rsbackend.py b/pylib/anki/rsbackend.py index 6ff70d95d..26d0eef66 100644 --- a/pylib/anki/rsbackend.py +++ b/pylib/anki/rsbackend.py @@ -176,6 +176,11 @@ def proto_progress_to_native(progress: pb.Progress) -> Progress: else: assert_impossible_literal(kind) +def _on_progress(progress_bytes: bytes) -> bool: + progress = pb.Progress() + progress.ParseFromString(progress_bytes) + native_progress = proto_progress_to_native(progress) + return hooks.bg_thread_progress_callback(True, native_progress) class RustBackend: def __init__( @@ -191,13 +196,7 @@ class RustBackend: log_path=log_path, ) self._backend = ankirspy.open_backend(init_msg.SerializeToString()) - self._backend.set_progress_callback(self._on_progress) - - def _on_progress(self, progress_bytes: bytes) -> bool: - progress = pb.Progress() - progress.ParseFromString(progress_bytes) - native_progress = proto_progress_to_native(progress) - return hooks.bg_thread_progress_callback(True, native_progress) + self._backend.set_progress_callback(_on_progress) def _run_command( self, input: pb.BackendInput, release_gil: bool = False