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
|
from plyer import notification
|
||||||
PLYER_AVAILABLE = True
|
PLYER_AVAILABLE = True
|
||||||
except ImportError:
|
except ImportError:
|
||||||
logger.warning("plyer not found. Notifications will be printed to stdout.")
|
logger.warning("plyer not found. Will try win10toast.")
|
||||||
PLYER_AVAILABLE = False
|
PLYER_AVAILABLE = False
|
||||||
|
|
||||||
|
try:
|
||||||
|
from win10toast import ToastNotifier
|
||||||
|
WIN10TOAST_AVAILABLE = True
|
||||||
|
toaster = ToastNotifier()
|
||||||
|
except ImportError:
|
||||||
|
WIN10TOAST_AVAILABLE = False
|
||||||
|
|
||||||
class Notifier:
|
class Notifier:
|
||||||
def notify(self, title, message):
|
def notify(self, title, message):
|
||||||
logger.info(f"Notification: {title} - {message}")
|
logger.info(f"Notification: {title} - {message}")
|
||||||
|
|
||||||
|
# Try plyer first
|
||||||
if PLYER_AVAILABLE:
|
if PLYER_AVAILABLE:
|
||||||
try:
|
try:
|
||||||
notification.notify(
|
notification.notify(
|
||||||
title=title,
|
title=title,
|
||||||
message=message,
|
message=message,
|
||||||
app_name="Git Monitor",
|
app_name="Git Monitor"
|
||||||
# timeout=10
|
|
||||||
)
|
)
|
||||||
|
return
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Error showing notification: {e}")
|
logger.error(f"Plyer notification failed: {e}. Trying fallback...")
|
||||||
else:
|
|
||||||
print(f"[{title}] {message}")
|
# 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()
|
notifier = Notifier()
|
||||||
|
|||||||
Reference in New Issue
Block a user