From c35c01dbaef77cb2897bf32730c09e4707ffa0cd Mon Sep 17 00:00:00 2001 From: "Max P." Date: Mon, 24 Mar 2025 13:50:29 +0100 Subject: [PATCH] Improves error handling in notification function Updates the notify function to handle subprocess errors gracefully, ensuring better feedback and preventing crashes when notifications fail. --- voice_to_text_tray.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/voice_to_text_tray.py b/voice_to_text_tray.py index b382283..d8fc92f 100755 --- a/voice_to_text_tray.py +++ b/voice_to_text_tray.py @@ -4,6 +4,7 @@ import subprocess import os import threading import socket +import json import requests import json from PyQt5.QtWidgets import QApplication, QSystemTrayIcon, QMenu, QAction @@ -20,8 +21,12 @@ def read_configurations(): CONFIGURATION = read_configurations() CURRENT_PRESET = CONFIGURATION["presets"][0] # Default to first preset -def notify(title, message): - subprocess.run(["notify-send", "-a", "Voice to Text", "-i", "audio-input-microphone", title, message], check=True) +def notify(title: str, message: str) -> None: + try: + subprocess.run(["notify-send", "-a", "Voice to Text", "-i", "audio-input-microphone", title, message], check=True) + except subprocess.CalledProcessError as e: + print("Fehler beim Benachrichtigen mit 'notify-send'.") + print(e) # === Worker Thread for Whisper + Ollama === class WhisperWorker(QThread):