From c8b4a2b1eda5562106d0408197d9bfbe1c61d8bc Mon Sep 17 00:00:00 2001 From: end-4 <97237370+end-4@users.noreply.github.com> Date: Sat, 15 Mar 2025 17:00:21 +0100 Subject: [PATCH] improve handling of chromium notifications (#964) --- .../modules/.commonwidgets/notification.js | 30 +++++++++++++++++-- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/.config/ags/modules/.commonwidgets/notification.js b/.config/ags/modules/.commonwidgets/notification.js index 85ee86bad..7a8b4936c 100644 --- a/.config/ags/modules/.commonwidgets/notification.js +++ b/.config/ags/modules/.commonwidgets/notification.js @@ -25,6 +25,15 @@ function exists(widget) { return widget !== null; } +function processNotificationBody(body, appEntry) { + // Only process Chrome/Chromium notifications + if (appEntry?.toLowerCase().includes('chrome')) { + // Remove the first line + return body.split('\n\n').slice(1).join('\n\n'); + } + return body; +} + const getFriendlyNotifTimeString = (timeObject) => { const messageTime = GLib.DateTime.new_from_unix_local(timeObject); const oneMinuteAgo = GLib.DateTime.new_now_local().add_seconds(-60); @@ -39,7 +48,22 @@ const getFriendlyNotifTimeString = (timeObject) => { } const NotificationIcon = (notifObject) => { - // { appEntry, appIcon, image }, urgency = 'normal' + + if (notifObject.hints?.image_path?.deepUnpack) { + const imagePath = notifObject.hints.image_path.deepUnpack(); + return Box({ + valign: Gtk.Align.CENTER, + hexpand: false, + className: 'notif-icon', + css: ` + background-image: url("${imagePath}"); + background-size: auto 100%; + background-repeat: no-repeat; + background-position: center; + `, + }); + } + if (notifObject.image) { return Box({ valign: Gtk.Align.CENTER, @@ -168,7 +192,7 @@ export default ({ justify: Gtk.Justification.LEFT, maxWidthChars: 1, truncate: 'end', - label: notifObject.body.split("\n")[0], + label: processNotificationBody(notifObject.body, notifObject.appEntry).split("\n")[0] }), }); const notifTextExpanded = Revealer({ @@ -187,7 +211,7 @@ export default ({ justify: Gtk.Justification.LEFT, maxWidthChars: 1, wrap: true, - label: notifObject.body, + label: processNotificationBody(notifObject.body, notifObject.appEntry) }), Box({ className: 'notif-actions spacing-h-5',