From c80f3aa243bc86896ef91f806960d0bc71958b8d Mon Sep 17 00:00:00 2001 From: AuroraWright Date: Tue, 1 Apr 2025 01:36:27 +0200 Subject: [PATCH] Isolate window capture code --- owocr/run.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/owocr/run.py b/owocr/run.py index b4f2f5c..ac0e3f0 100644 --- a/owocr/run.py +++ b/owocr/run.py @@ -648,7 +648,12 @@ def run(read_from=None, """ if read_from == 'screencapture' and sys.platform not in ('darwin', 'win32'): - active_window_name = pywinctl.getActiveWindowTitle() + window_capture_available = False + try: + active_window_name = pywinctl.getActiveWindowTitle() + window_capture_available = True + except Exception: + pass logger.configure(handlers=[{'sink': sys.stderr, 'format': config.get_general('logger_format')}]) @@ -876,6 +881,9 @@ def run(read_from=None, windows_window_tracker.start() logger.opt(ansi=True).info(f'Selected window: {window_title}') else: + if not window_capture_available: + raise ValueError('Window capture is not available on your setup') + sct = mss.mss() window_title = None window_titles = pywinctl.getAllTitles()