From 726560ddb309242cfad1f014baf48b835469a3ba Mon Sep 17 00:00:00 2001 From: deeplow Date: Mon, 19 Jun 2023 11:32:22 +0100 Subject: [PATCH] Add progress reports on Qubes (GUI) Fixes #429 --- dangerzone/conversion/common.py | 8 ++++++-- dangerzone/isolation_provider/qubes.py | 7 ++++--- 2 files changed, 10 insertions(+), 5 deletions(-) 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 d11070640..507b0fc8f 100644 --- a/dangerzone/isolation_provider/qubes.py +++ b/dangerzone/isolation_provider/qubes.py @@ -147,9 +147,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"