💥 fix(notifications): body not showing if notification uses markup with more than one word space

This commit is contained in:
retrozinndev
2025-06-08 16:33:07 -03:00
parent 9be644b2aa
commit c9a89ea9bf
+15 -15
View File
@@ -4,19 +4,25 @@ import { Separator } from "./Separator";
import { HistoryNotification, Notifications } from "../scripts/notifications"; import { HistoryNotification, Notifications } from "../scripts/notifications";
import { GLib } from "astal"; import { GLib } from "astal";
import { getAppIcon } from "../scripts/apps"; import { getAppIcon } from "../scripts/apps";
import Pango from "gi://Pango?version=1.0";
export let NOTIFICATION_MAX_WORD_CHAR_SIZE = 25;
function getNotificationImage(notif: AstalNotifd.Notification|HistoryNotification): (string|undefined) { function getNotificationImage(notif: AstalNotifd.Notification|HistoryNotification): (string|undefined) {
const img = notif.image ?? notif.appIcon; const img = notif.image || notif.appIcon;
if(!img) return undefined;
if(!img.includes('/')) return undefined; if(!img)
return undefined;
if(img.startsWith('/')) switch(true) {
case /^[/]/.test(img):
return `file://${img}`; return `file://${img}`;
if(img.startsWith('~') || img.startsWith("file://~")) case /^[~]/.test(img):
return `file://${GLib.get_home_dir()}/${img.replace(/^(file\:\/\/|\~|file\:\/\/~)/g, "")}`; case /^file:\/\/[~]/i.test(img):
return `file://${GLib.get_home_dir()}/${img.replace(/^(file\:\/\/|[~]|file\:\/\[~])/i, "")}`;
}
return img; return img;
} }
@@ -30,14 +36,6 @@ export function NotificationWidget(notification: AstalNotifd.Notification|number
AstalNotifd.get_default().get_notification(notification) AstalNotifd.get_default().get_notification(notification)
: notification; : notification;
const body: string = notification.body.split(' ').map(strPart => {
if(/^\<(.*)\>/.test(strPart) || /<\/(.*)\>$/.test(strPart))
return strPart;
return strPart.length >= 25 ? `${strPart.substring(0, 22)}...`
: strPart
}).join(' ');
return new Widget.EventBox({ return new Widget.EventBox({
onClick: () => { onClick: () => {
if(notification instanceof AstalNotifd.Notification) { if(notification instanceof AstalNotifd.Notification) {
@@ -139,7 +137,9 @@ export function NotificationWidget(notification: AstalNotifd.Notification|number
xalign: 0, xalign: 0,
truncate: false, truncate: false,
wrap: true, wrap: true,
label: body.replace(/\&/g, "&amp;") singleLineMode: false,
wrapMode: Pango.WrapMode.WORD_CHAR,
label: notification.body.replace(/&/g, "&amp;")
} as Widget.LabelProps) } as Widget.LabelProps)
] ]
} as Widget.BoxProps) } as Widget.BoxProps)