From cc16d46211124178a66b7d917187372488de1ece Mon Sep 17 00:00:00 2001 From: retrozinndev Date: Fri, 18 Apr 2025 21:49:33 -0300 Subject: [PATCH] :boom: ags(notifications): also check `AstalNotifd.Notification.appIcon` for image path this commit fixes issues with hyprshot screenshot notification and markup issues with the new truncating method --- ags/widget/Notification.ts | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/ags/widget/Notification.ts b/ags/widget/Notification.ts index 1a7bb24..691def3 100644 --- a/ags/widget/Notification.ts +++ b/ags/widget/Notification.ts @@ -15,6 +15,21 @@ export function getUrgencyString(notif: AstalNotifd.Notification) { return "normal"; } +function getNotificationImage(notif: AstalNotifd.Notification|HistoryNotification): (string|undefined) { + const img = notif.image ?? notif.appIcon; + if(!img) return undefined; + + if(!img.includes('/')) return undefined; + + if(img.startsWith('/')) + return `file://${img}`; + + if(img.startsWith('~') || img.startsWith("file://~")) + return `file://${GLib.get_home_dir()}/${img.replace(/^(file\:\/\/|\~|file\:\/\/~)/g, "")}`; + + return img; +} + export function NotificationWidget(notification: AstalNotifd.Notification|number|HistoryNotification, onClose?: (notif: AstalNotifd.Notification|HistoryNotification) => void, showTime?: boolean /* It's showTime :speaking_head: :boom: :bangbang: */): Gtk.Widget { @@ -23,9 +38,12 @@ export function NotificationWidget(notification: AstalNotifd.Notification|number AstalNotifd.get_default().get_notification(notification) : notification; - const body: string = notification.body.split(' ').map(strPart => - strPart.length >= 25 ? `${strPart.substring(0, 22)}...` - : strPart).join(' '); + const body: string = notification.body.split(' ').map(strPart => { + if(/^\<.*\>.*\<.*\>$/.test(strPart)) return strPart; + + return strPart.length >= 25 ? `${strPart.substring(0, 22)}...` + : strPart + }).join(' '); return new Widget.EventBox({ onClick: () => { @@ -100,8 +118,12 @@ export function NotificationWidget(notification: AstalNotifd.Notification|number children: [ new Widget.Box({ className: "image", - visible: Boolean(notification.image), - css: `box.image { background-image: url('${notification.image}'); }` + setup: (box) => { + const img = getNotificationImage(notification); + + box.set_visible(Boolean(img)); + img && box.set_css(`background-image: image(url("${img}"))`); + } } as Widget.BoxProps), new Widget.Box({ className: "text",