diff options
| author | 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> | 2026-03-12 22:21:05 +1100 |
|---|---|---|
| committer | 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> | 2026-03-12 22:21:05 +1100 |
| commit | 314301157e6f2d9859cc51272b5f8a4f70cc05dd (patch) | |
| tree | a5b1c815f3e37593a9d7a0f9331187c5a37ee0ed | |
| parent | workspaces: replace reduce with for loop for occupied map (diff) | |
| download | caelestia-shell-314301157e6f2d9859cc51272b5f8a4f70cc05dd.tar.gz caelestia-shell-314301157e6f2d9859cc51272b5f8a4f70cc05dd.tar.bz2 caelestia-shell-314301157e6f2d9859cc51272b5f8a4f70cc05dd.zip | |
notifs: single-pass derived properties in NotifGroup
| -rw-r--r-- | modules/lock/NotifGroup.qml | 27 | ||||
| -rw-r--r-- | modules/sidebar/NotifGroup.qml | 34 |
2 files changed, 54 insertions, 7 deletions
diff --git a/modules/lock/NotifGroup.qml b/modules/lock/NotifGroup.qml index 7796090..85c5ec4 100644 --- a/modules/lock/NotifGroup.qml +++ b/modules/lock/NotifGroup.qml @@ -17,9 +17,30 @@ StyledRect { required property string modelData readonly property list<var> notifs: Notifs.list.filter(notif => notif.appName === modelData) - readonly property string image: notifs.find(n => n.image.length > 0)?.image ?? "" - readonly property string appIcon: notifs.find(n => n.appIcon.length > 0)?.appIcon ?? "" - readonly property string urgency: notifs.some(n => n.urgency === NotificationUrgency.Critical) ? "critical" : notifs.some(n => n.urgency === NotificationUrgency.Normal) ? "normal" : "low" + readonly property var props: { + let img = ""; + let icon = ""; + let hasCritical = false; + let hasNormal = false; + for (const n of notifs) { + if (!img && n.image.length > 0) + img = n.image; + if (!icon && n.appIcon.length > 0) + icon = n.appIcon; + if (n.urgency === NotificationUrgency.Critical) + hasCritical = true; + else if (n.urgency === NotificationUrgency.Normal) + hasNormal = true; + } + return { + img, + icon, + urgency: hasCritical ? "critical" : hasNormal ? "normal" : "low" + }; + } + readonly property string image: props.img + readonly property string appIcon: props.icon + readonly property string urgency: props.urgency property bool expanded diff --git a/modules/sidebar/NotifGroup.qml b/modules/sidebar/NotifGroup.qml index 16aac33..4e338da 100644 --- a/modules/sidebar/NotifGroup.qml +++ b/modules/sidebar/NotifGroup.qml @@ -19,10 +19,36 @@ StyledRect { required property var visibilities readonly property list<var> notifs: Notifs.list.filter(n => n.appName === modelData) - readonly property int notifCount: notifs.reduce((acc, n) => n.closed ? acc : acc + 1, 0) - readonly property string image: notifs.find(n => !n.closed && n.image.length > 0)?.image ?? "" - readonly property string appIcon: notifs.find(n => !n.closed && n.appIcon.length > 0)?.appIcon ?? "" - readonly property int urgency: notifs.some(n => !n.closed && n.urgency === NotificationUrgency.Critical) ? NotificationUrgency.Critical : notifs.some(n => n.urgency === NotificationUrgency.Normal) ? NotificationUrgency.Normal : NotificationUrgency.Low + readonly property var groupProps: { + let count = 0; + let img = ""; + let icon = ""; + let hasCritical = false; + let hasNormal = false; + for (const n of notifs) { + if (!n.closed) { + count++; + if (!img && n.image.length > 0) + img = n.image; + if (!icon && n.appIcon.length > 0) + icon = n.appIcon; + if (n.urgency === NotificationUrgency.Critical) + hasCritical = true; + else if (n.urgency === NotificationUrgency.Normal) + hasNormal = true; + } + } + return { + count, + img, + icon, + urgency: hasCritical ? NotificationUrgency.Critical : hasNormal ? NotificationUrgency.Normal : NotificationUrgency.Low + }; + } + readonly property int notifCount: groupProps.count + readonly property string image: groupProps.img + readonly property string appIcon: groupProps.icon + readonly property int urgency: groupProps.urgency readonly property int nonAnimHeight: { const headerHeight = header.implicitHeight + (root.expanded ? Math.round(Appearance.spacing.small / 2) : 0); |