Style Single Notification As Normal One

This commit is contained in:
tr1x_em committed 2025-08-14 16:05:29 +05:30
1 parent d1c0a2d537
commit 31efb0e03f
1 file changed
+113 -84
+113 -84
View File
@@ -62,66 +62,69 @@ class ExpandableNotificationGroup(Box):
if num_notifications == 1: if num_notifications == 1:
# Single notification - no stacking needed # Single notification - no stacking needed
single_notification = Box( notification_widget = NotificationCenterWidget(
name="single-notification-content", notification=latest_notification
spacing=8,
children=[
Box(
name="notification-image",
children=CustomImage(
pixbuf=self._get_notification_pixbuf(
latest_notification._notification
) )
), # single_notification = Box(
), # name="single-notification-content",
Box( # spacing=8,
name="notification-text", # children=[
orientation="v", # Box(
v_align="center", # name="notification-image",
h_expand=True, # children=CustomImage(
children=[ # pixbuf=self._get_notification_pixbuf(
Box( # latest_notification._notification
name="notification-summary-box", # )
orientation="h", # ),
children=[ # ),
Label( # Box(
name="notification-summary", # name="notification-text",
markup=f"<b>{self.app_name}</b>", # orientation="v",
h_align="start", # v_align="center",
ellipsization="end", # h_expand=True,
), # children=[
], # Box(
), # name="notification-summary-box",
Label( # orientation="h",
name="notification-body", # children=[
markup=latest_notification._notification.summary.replace( # Label(
"\n", " " # name="notification-summary",
), # markup=f"<b>{self.app_name}</b>",
max_chars_width=35, # h_align="start",
h_align="start", # ellipsization="end",
ellipsization="end", # ),
), # ],
], # ),
), # Label(
Box( # name="notification-body",
orientation="v", # markup=latest_notification._notification.summary.replace(
children=[ # "\n", " "
Button( # ),
name="notification-close", # max_chars_width=35,
image=CustomImage( # h_align="start",
icon_name="close-symbolic", icon_size=18 # ellipsization="end",
), # ),
visible=True, # ],
on_clicked=lambda *_: self._close_single_notification_and_stop_propagation( # ),
latest_notification # Box(
), # orientation="v",
), # children=[
Box(v_expand=True), # Button(
], # name="notification-close",
), # image=CustomImage(
], # icon_name="close-symbolic", icon_size=18
) # ),
self.collapsed_eventbox.add(single_notification) # visible=True,
# on_clicked=lambda *_: self._close_single_notification_and_stop_propagation(
# latest_notification
# ),
# ),
# Box(v_expand=True),
# ],
# ),
# ],
# )
self.collapsed_eventbox.add(notification_widget)
else: else:
# Multiple notifications - create stacked effect # Multiple notifications - create stacked effect
# Create container for the entire stack # Create container for the entire stack
@@ -331,7 +334,9 @@ class ExpandableNotificationGroup(Box):
if cache_path and cache_key: if cache_path and cache_key:
cached_pixbuf = get_cached_notification_image(cache_key) cached_pixbuf = get_cached_notification_image(cache_key)
if cached_pixbuf: if cached_pixbuf:
logger.debug(f"Cached and using notification image: {cache_key}") logger.debug(
f"Cached and using notification image: {cache_key}"
)
return cached_pixbuf return cached_pixbuf
# Direct fallback if caching succeeded but loading failed # Direct fallback if caching succeeded but loading failed
@@ -363,9 +368,8 @@ class ExpandableNotificationGroup(Box):
def on_clicked(self, widget, event): def on_clicked(self, widget, event):
if event.button == 1: # Left click if event.button == 1: # Left click
if ( # Always allow expansion, even for single notifications
len(self.notifications) > 1 # This ensures single notifications can show their expanded entry view
): # Only expand if there are multiple notifications
self.expand() self.expand()
return True return True
@@ -419,40 +423,58 @@ class ExpandableNotificationGroup(Box):
for notification in self.notifications: for notification in self.notifications:
try: try:
# Get notification cache metadata for cleanup # Get notification cache metadata for cleanup
cache_metadata = getattr(notification, 'cache_metadata', {}) cache_metadata = getattr(notification, "cache_metadata", {})
# Clean up caches using stored metadata # Clean up caches using stored metadata
from modules.notification.notification import cleanup_notification_specific_caches from modules.notification.notification import (
cleanup_notification_specific_caches( cleanup_notification_specific_caches,
app_icon_source=notification._notification.app_icon,
notification_image_cache_key=cache_metadata.get('notification_image_cache_key')
) )
logger.debug(f"Cleaned up caches for notification ID: {notification._notification.id}") cleanup_notification_specific_caches(
app_icon_source=notification._notification.app_icon,
notification_image_cache_key=cache_metadata.get(
"notification_image_cache_key"
),
)
logger.debug(
f"Cleaned up caches for notification ID: {notification._notification.id}"
)
notification_service.remove_cached_notification(notification.cache_id) notification_service.remove_cached_notification(notification.cache_id)
except Exception as e: except Exception as e:
logger.error(f"Error removing notification {notification.cache_id}: {e}") logger.error(
f"Error removing notification {notification.cache_id}: {e}"
)
def _close_single_notification(self, notification): def _close_single_notification(self, notification):
"""Close a single notification from this group with proper cache cleanup""" """Close a single notification from this group with proper cache cleanup"""
try: try:
# Get notification cache metadata for cleanup # Get notification cache metadata for cleanup
cache_metadata = getattr(notification, 'cache_metadata', {}) cache_metadata = getattr(notification, "cache_metadata", {})
# Clean up caches using stored metadata # Clean up caches using stored metadata
from modules.notification.notification import cleanup_notification_specific_caches from modules.notification.notification import (
cleanup_notification_specific_caches( cleanup_notification_specific_caches,
app_icon_source=notification._notification.app_icon,
notification_image_cache_key=cache_metadata.get('notification_image_cache_key')
) )
logger.debug(f"Cleaned up caches for notification ID: {notification._notification.id}") cleanup_notification_specific_caches(
app_icon_source=notification._notification.app_icon,
notification_image_cache_key=cache_metadata.get(
"notification_image_cache_key"
),
)
logger.debug(
f"Cleaned up caches for notification ID: {notification._notification.id}"
)
notification_service.remove_cached_notification(notification.cache_id) notification_service.remove_cached_notification(notification.cache_id)
logger.debug(f"Closed single notification: {notification.cache_id}") logger.debug(f"Closed single notification: {notification.cache_id}")
except Exception as e: except Exception as e:
logger.error(f"Error removing single notification {notification.cache_id}: {e}") logger.error(
f"Error removing single notification {notification.cache_id}: {e}"
)
def _close_single_notification_and_stop_propagation(self, notification): def _close_single_notification_and_stop_propagation(self, notification):
"""Close notification and prevent click from expanding the group""" """Close notification and prevent click from expanding the group"""
@@ -573,18 +595,25 @@ class NotificationCenterWidget(NotificationWidget):
def _on_close_clicked(self, *args): def _on_close_clicked(self, *args):
try: try:
# Get notification cache metadata for cleanup # Get notification cache metadata for cleanup
cache_metadata = getattr(self, 'cache_metadata', {}) cache_metadata = getattr(self, "cache_metadata", {})
if hasattr(self.notification, '_cache_metadata'): if hasattr(self.notification, "_cache_metadata"):
cache_metadata = self.notification._cache_metadata cache_metadata = self.notification._cache_metadata
# Clean up caches using stored metadata # Clean up caches using stored metadata
from modules.notification.notification import cleanup_notification_specific_caches from modules.notification.notification import (
cleanup_notification_specific_caches( cleanup_notification_specific_caches,
app_icon_source=self.notification.app_icon,
notification_image_cache_key=cache_metadata.get('notification_image_cache_key')
) )
logger.debug(f"Cleaned up caches for notification center ID: {self.notification.id}") cleanup_notification_specific_caches(
app_icon_source=self.notification.app_icon,
notification_image_cache_key=cache_metadata.get(
"notification_image_cache_key"
),
)
logger.debug(
f"Cleaned up caches for notification center ID: {self.notification.id}"
)
notification_service.remove_cached_notification(self.notification_id) notification_service.remove_cached_notification(self.notification_id)
except Exception as e: except Exception as e: