From 1d5206db5bcba6d8725c2fba14bba48a8f0131d8 Mon Sep 17 00:00:00 2001 From: AuroraWright Date: Mon, 24 Jun 2024 17:28:05 +0200 Subject: [PATCH] Support new desktop-notifier --- owocr/run.py | 20 +++++--------------- setup.py | 4 ++-- 2 files changed, 7 insertions(+), 17 deletions(-) diff --git a/owocr/run.py b/owocr/run.py index 4c6dc96..ce84968 100644 --- a/owocr/run.py +++ b/owocr/run.py @@ -18,7 +18,7 @@ from PIL import Image from PIL import UnidentifiedImageError from loguru import logger from pynput import keyboard -from desktop_notifier import DesktopNotifier +from desktop_notifier import DesktopNotifierSync import psutil import inspect @@ -296,7 +296,7 @@ def pause_handler(is_combo=True): message = 'Paused!' if is_combo: - notifier.send_sync(title='owocr', message=message) + notifier.send(title='owocr', message=message) logger.info(message) paused = not paused @@ -316,7 +316,7 @@ def engine_change_handler(user_input='s', is_combo=True): if engine_index != old_engine_index: new_engine_name = engine_instances[engine_index].readable_name if is_combo: - notifier.send_sync(title='owocr', message=f'Switched to {new_engine_name}') + notifier.send(title='owocr', message=f'Switched to {new_engine_name}') engine_color = config.get_general('engine_color') logger.opt(ansi=True).info(f'Switched to <{engine_color}>{new_engine_name}!') @@ -413,13 +413,6 @@ def on_window_moved(pos): sct_params['top'] = pos[1] -async def fix_windows_notifications(): - try: - await notifier.request_authorisation() - except OSError: - pass - - def normalize_macos_clipboard(img): ns_data = NSData.dataWithBytes_length_(img, len(img)) ns_image = NSImage.alloc().initWithData_(ns_data) @@ -474,7 +467,7 @@ def process_and_write_results(img_or_path, write_to, notifications, enable_filte text = post_process(text) logger.opt(ansi=True).info(f'Text recognized in {t1 - t0:0.03f}s using <{engine_color}>{engine_instance.readable_name}: {text}') if notifications: - notifier.send_sync(title='owocr', message='Text recognized: ' + text) + notifier.send(title='owocr', message='Text recognized: ' + text) if write_to == 'websocket': websocket_server_thread.send_text(text) @@ -591,7 +584,7 @@ def run(read_from=None, engine_color = config.get_general('engine_color') delay_secs = config.get_general('delay_secs') screen_capture_on_combo = False - notifier = DesktopNotifier() + notifier = DesktopNotifierSync() key_combos = {} if combo_pause != '': @@ -605,9 +598,6 @@ def run(read_from=None, user_input_thread = threading.Thread(target=user_input_thread_run, daemon=True) user_input_thread.start() - if sys.platform == 'win32': - asyncio.run(fix_windows_notifications()) - if read_from == 'websocket' or write_to == 'websocket': global websocket_server_thread websocket_server_thread = WebsocketServerThread(read_from == 'websocket') diff --git a/setup.py b/setup.py index 513e85e..7820e67 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ long_description = (Path(__file__).parent / "README.md").read_text('utf-8') setup( name="owocr", - version='1.7.4', + version='1.7.5', description="Japanese OCR", long_description=long_description, long_description_content_type="text/markdown", @@ -27,7 +27,7 @@ setup( "pyperclipfix", "pynput", "websockets", - "desktop-notifier", + "desktop-notifier>=5.0.0", "mss", "pysbd", "langid",