Support new desktop-notifier

This commit is contained in:
AuroraWright
2024-06-24 17:28:05 +02:00
parent a7b832f6f2
commit 1d5206db5b
2 changed files with 7 additions and 17 deletions

View File

@@ -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}</{engine_color}>!')
@@ -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}</{engine_color}>: {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')

View File

@@ -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",