"""Shared progress state — polled by UI timer during long translation.""" from __future__ import annotations import threading from dataclasses import dataclass @dataclass class ProgressState: pct: float = 0.0 message: str = "Sẵn sàng." running: bool = False _lock = threading.Lock() _state = ProgressState() def set_progress(pct: float, message: str, *, running: bool = True) -> None: with _lock: _state.pct = max(0.0, min(100.0, float(pct))) _state.message = message _state.running = running def finish_progress(message: str) -> None: with _lock: _state.pct = 100.0 _state.message = message _state.running = False def reset_progress(message: str = "Sẵn sàng.") -> None: with _lock: _state.pct = 0.0 _state.message = message _state.running = False def snapshot() -> ProgressState: with _lock: return ProgressState( pct=_state.pct, message=_state.message, running=_state.running, )