Add progress reports on Qubes (GUI)

Fixes #429
This commit is contained in:
deeplow 2023-06-19 11:32:22 +01:00
parent bf38c24d99
commit ef41cab76e
No known key found for this signature in database
GPG key ID: 577982871529A52A
2 changed files with 10 additions and 5 deletions

View file

@ -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 @@ class DangerzoneConverter:
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)}

View file

@ -131,9 +131,10 @@ class Qubes(IsolationProvider):
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"