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 Jul 13, 2023
1 parent bf38c24 commit ef41cab
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 @@ -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"
Expand Down

0 comments on commit ef41cab

Please sign in to comment.