Improves error handling in notification function

Updates the notify function to handle subprocess errors gracefully, ensuring better feedback and preventing crashes when notifications fail.
This commit is contained in:
2025-03-24 13:50:29 +01:00
parent 58cec63314
commit c35c01dbae

View File

@@ -4,6 +4,7 @@ import subprocess
import os import os
import threading import threading
import socket import socket
import json
import requests import requests
import json import json
from PyQt5.QtWidgets import QApplication, QSystemTrayIcon, QMenu, QAction from PyQt5.QtWidgets import QApplication, QSystemTrayIcon, QMenu, QAction
@@ -20,8 +21,12 @@ def read_configurations():
CONFIGURATION = read_configurations() CONFIGURATION = read_configurations()
CURRENT_PRESET = CONFIGURATION["presets"][0] # Default to first preset CURRENT_PRESET = CONFIGURATION["presets"][0] # Default to first preset
def notify(title, message): def notify(title: str, message: str) -> None:
try:
subprocess.run(["notify-send", "-a", "Voice to Text", "-i", "audio-input-microphone", title, message], check=True) 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 === # === Worker Thread for Whisper + Ollama ===
class WhisperWorker(QThread): class WhisperWorker(QThread):