fix: add win10toast fallback for notifications if plyer fails in PyInstaller
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user