Skip to content

Commit

Permalink
Add progress reports on Qubes (GUI)
Browse files Browse the repository at this point in the history
Fixes #429
  • Loading branch information
deeplow committed Jun 19, 2023
1 parent 9139406 commit 797ad92
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
8 changes: 6 additions & 2 deletions dangerzone/conversion/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)}
Expand Down
7 changes: 4 additions & 3 deletions dangerzone/isolation_provider/qubes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 797ad92

Please sign in to comment.