🐛 fix(notification): handle potential errors when accessing image_pixbuf
This commit is contained in:
2 files changed
+53
-39
No files matched your search
@@ -96,19 +96,23 @@ class NotificationBox(Box):
|
||||
if self.timeout_ms > 0:
|
||||
self.start_timeout()
|
||||
|
||||
if self.notification.image_pixbuf:
|
||||
cache_path = cache_notification_pixbuf(self)
|
||||
if cache_path:
|
||||
self.cached_image_path = cache_path
|
||||
|
||||
# Try to access image_pixbuf with error handling
|
||||
try:
|
||||
if self.notification.image_pixbuf:
|
||||
cache_path = cache_notification_pixbuf(self)
|
||||
if cache_path:
|
||||
self.cached_image_path = cache_path
|
||||
else:
|
||||
logger.warning(
|
||||
f"NotificationBox {
|
||||
self.uuid
|
||||
}: Caching failed, cached_image_path not set."
|
||||
)
|
||||
else:
|
||||
logger.warning(
|
||||
f"NotificationBox {
|
||||
self.uuid
|
||||
}: Caching failed, cached_image_path not set."
|
||||
)
|
||||
else:
|
||||
logger.debug(f"NotificationBox {self.uuid}: No image to cache.")
|
||||
logger.debug(f"NotificationBox {self.uuid}: No image to cache.")
|
||||
except Exception as e:
|
||||
logger.debug(f"NotificationBox {self.uuid}: Error accessing image_pixbuf: {e}")
|
||||
# Continue without image - this is not a critical error
|
||||
|
||||
content = self.create_content()
|
||||
action_buttons = self.create_action_buttons()
|
||||
@@ -439,8 +443,11 @@ class NotificationContainer(Box):
|
||||
if notification_history_instance.do_not_disturb_enabled:
|
||||
notification = fabric_notif.get_notification_from_id(id)
|
||||
new_box = NotificationBox(notification)
|
||||
if notification.image_pixbuf:
|
||||
cache_notification_pixbuf(new_box)
|
||||
try:
|
||||
if notification.image_pixbuf:
|
||||
cache_notification_pixbuf(new_box)
|
||||
except Exception as e:
|
||||
logger.debug(f"Error accessing image_pixbuf for notification {id}: {e}")
|
||||
new_box.set_is_history(True)
|
||||
notification_history_instance.add_notification(new_box)
|
||||
return
|
||||
|
||||
+32
-25
@@ -45,28 +45,32 @@ class HistoricalNotification:
|
||||
def cache_notification_pixbuf(notification_box):
|
||||
"""Cache notification image to disk and return cache file path"""
|
||||
notification = notification_box.notification
|
||||
if notification.image_pixbuf:
|
||||
os.makedirs(PERSISTENT_DIR, exist_ok=True)
|
||||
cache_file = os.path.join(
|
||||
PERSISTENT_DIR,
|
||||
f"{NOTIFICATION_IMAGE_PREFIX}{notification_box.uuid}{
|
||||
NOTIFICATION_IMAGE_SUFFIX
|
||||
}",
|
||||
)
|
||||
|
||||
try:
|
||||
scaled = notification.image_pixbuf.scale_simple(
|
||||
DEFAULT_NOTIFICATION_IMAGE_SIZE,
|
||||
DEFAULT_NOTIFICATION_IMAGE_SIZE,
|
||||
GdkPixbuf.InterpType.BILINEAR,
|
||||
try:
|
||||
if notification.image_pixbuf:
|
||||
os.makedirs(PERSISTENT_DIR, exist_ok=True)
|
||||
cache_file = os.path.join(
|
||||
PERSISTENT_DIR,
|
||||
f"{NOTIFICATION_IMAGE_PREFIX}{notification_box.uuid}{
|
||||
NOTIFICATION_IMAGE_SUFFIX
|
||||
}",
|
||||
)
|
||||
scaled.savev(cache_file, "png", [], [])
|
||||
return cache_file
|
||||
except Exception as e:
|
||||
logger.error(f"Error caching image for notification {notification.id}: {e}")
|
||||
|
||||
try:
|
||||
scaled = notification.image_pixbuf.scale_simple(
|
||||
DEFAULT_NOTIFICATION_IMAGE_SIZE,
|
||||
DEFAULT_NOTIFICATION_IMAGE_SIZE,
|
||||
GdkPixbuf.InterpType.BILINEAR,
|
||||
)
|
||||
scaled.savev(cache_file, "png", [], [])
|
||||
return cache_file
|
||||
except Exception as e:
|
||||
logger.error(f"Error caching image for notification {notification.id}: {e}")
|
||||
return None
|
||||
else:
|
||||
logger.debug(f"Notification {notification.id} has no image_pixbuf to cache.")
|
||||
return None
|
||||
else:
|
||||
logger.debug(f"Notification {notification.id} has no image_pixbuf to cache.")
|
||||
except Exception as e:
|
||||
logger.debug(f"Error accessing image_pixbuf for notification {notification.id}: {e}")
|
||||
return None
|
||||
|
||||
|
||||
@@ -109,11 +113,14 @@ def load_scaled_pixbuf(notification_box, width, height):
|
||||
)
|
||||
|
||||
# Fall back to notification image_pixbuf
|
||||
if notification.image_pixbuf:
|
||||
pixbuf = notification.image_pixbuf.scale_simple(
|
||||
width, height, GdkPixbuf.InterpType.BILINEAR
|
||||
)
|
||||
return pixbuf
|
||||
try:
|
||||
if notification.image_pixbuf:
|
||||
pixbuf = notification.image_pixbuf.scale_simple(
|
||||
width, height, GdkPixbuf.InterpType.BILINEAR
|
||||
)
|
||||
return pixbuf
|
||||
except Exception as e:
|
||||
logger.debug(f"Error accessing image_pixbuf for notification {notification.id}: {e}")
|
||||
|
||||
# Fall back to app icon
|
||||
return get_app_icon_pixbuf(notification.app_icon, width, height)
|
||||
|
||||
Reference in new issue
Block a user