diff --git a/dangerzone/conversion/common.py b/dangerzone/conversion/common.py index d0760aa50..5f6de4232 100644 --- a/dangerzone/conversion/common.py +++ b/dangerzone/conversion/common.py @@ -100,8 +100,9 @@ async def run_command( class DangerzoneConverter: - def __init__(self) -> None: + def __init__(self, progress_callback: Optional[Callable] = None) -> None: self.percentage: float = 0.0 + self.progress_callback = progress_callback def calculate_timeout( self, size: float, pages: Optional[float] = None @@ -134,7 +135,10 @@ async def convert(self) -> None: pass def update_progress(self, text: str, *, error: bool = False) -> None: - if not running_on_qubes(): + if running_on_qubes(): + if self.progress_callback: + self.progress_callback(error, text, int(self.percentage)) + else: print( json.dumps( {"error": error, "text": text, "percentage": int(self.percentage)} diff --git a/dangerzone/isolation_provider/qubes.py b/dangerzone/isolation_provider/qubes.py index 2d1ddaf2e..9a9eb9df2 100644 --- a/dangerzone/isolation_provider/qubes.py +++ b/dangerzone/isolation_provider/qubes.py @@ -131,9 +131,10 @@ def _convert( os.environ["OCR"] = "1" os.environ["OCR_LANGUAGE"] = ocr_lang - asyncio.run( - PixelsToPDF().convert() - ) # TODO add progress updates on second stage + def print_progress_wrapper(error: bool, text: str, percentage: float) -> None: + self.print_progress(document, error, text, percentage) + + asyncio.run(PixelsToPDF(progress_callback=print_progress_wrapper).convert()) percentage = 100.0 text = "Safe PDF created"