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