From e1f8ee95da1582920415a91df6c0facaf781c1df Mon Sep 17 00:00:00 2001 From: bartool Date: Fri, 6 Mar 2026 20:05:24 +0100 Subject: [PATCH] fix: add win10toast fallback for notifications if plyer fails in PyInstaller --- git_monitor/notifier.py | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/git_monitor/notifier.py b/git_monitor/notifier.py index 3cf7488..69af373 100644 --- a/git_monitor/notifier.py +++ b/git_monitor/notifier.py @@ -4,23 +4,42 @@ try: from plyer import notification PLYER_AVAILABLE = True except ImportError: - logger.warning("plyer not found. Notifications will be printed to stdout.") + logger.warning("plyer not found. Will try win10toast.") PLYER_AVAILABLE = False +try: + from win10toast import ToastNotifier + WIN10TOAST_AVAILABLE = True + toaster = ToastNotifier() +except ImportError: + WIN10TOAST_AVAILABLE = False + class Notifier: def notify(self, title, message): logger.info(f"Notification: {title} - {message}") + + # Try plyer first if PLYER_AVAILABLE: try: notification.notify( title=title, message=message, - app_name="Git Monitor", - # timeout=10 + app_name="Git Monitor" ) + return except Exception as e: - logger.error(f"Error showing notification: {e}") - else: - print(f"[{title}] {message}") + logger.error(f"Plyer notification failed: {e}. Trying fallback...") + + # Fallback to win10toast + if WIN10TOAST_AVAILABLE: + try: + # threaded=True prevents blocking the app + toaster.show_toast(title, message, duration=5, threaded=True) + return + except Exception as e: + logger.error(f"win10toast notification failed: {e}") + + # Final fallback to stdout + print(f"[{title}] {message}") notifier = Notifier()