summaryrefslogtreecommitdiff
path: root/modules/notifications
diff options
context:
space:
mode:
Diffstat (limited to 'modules/notifications')
-rw-r--r--modules/notifications/Notification.qml50
1 files changed, 25 insertions, 25 deletions
diff --git a/modules/notifications/Notification.qml b/modules/notifications/Notification.qml
index 594d9de..cc446c9 100644
--- a/modules/notifications/Notification.qml
+++ b/modules/notifications/Notification.qml
@@ -13,12 +13,12 @@ StyledRect {
id: root
required property Notifs.Notif modelData
- readonly property bool hasImage: modelData.image.length > 0
- readonly property bool hasAppIcon: modelData.appIcon.length > 0
+ readonly property bool hasImage: modelData?.image.length > 0
+ readonly property bool hasAppIcon: modelData?.appIcon.length > 0
readonly property int nonAnimHeight: summary.implicitHeight + (root.expanded ? appName.height + body.height + actions.height + actions.anchors.topMargin : bodyPreview.height) + inner.anchors.margins * 2
property bool expanded
- color: root.modelData.urgency === NotificationUrgency.Critical ? Colours.palette.m3secondaryContainer : Colours.palette.m3surfaceContainer
+ color: root.modelData?.urgency === NotificationUrgency.Critical ? Colours.palette.m3secondaryContainer : Colours.palette.m3surfaceContainer
radius: Appearance.rounding.normal
implicitWidth: NotifsConfig.sizes.width
implicitHeight: inner.height
@@ -43,12 +43,12 @@ StyledRect {
onPressed: event => {
startY = event.y;
if (event.button === Qt.MiddleButton)
- root.modelData.notification.dismiss();
+ root.modelData?.notification.dismiss();
}
onReleased: event => {
if (Math.abs(root.x) < NotifsConfig.sizes.width * NotifsConfig.clearThreshold)
root.x = 0;
- else
+ else if (root.modelData)
root.modelData.popup = false;
}
onPositionChanged: event => {
@@ -62,8 +62,8 @@ StyledRect {
if (!NotifsConfig.actionOnClick || event.button !== Qt.LeftButton)
return;
- const actions = root.modelData.actions;
- if (actions.length === 1)
+ const actions = root.modelData?.actions;
+ if (actions?.length === 1)
actions[0].invoke();
}
}
@@ -109,7 +109,7 @@ StyledRect {
Image {
anchors.fill: parent
- source: Qt.resolvedUrl(root.modelData.image)
+ source: Qt.resolvedUrl(root.modelData?.image)
fillMode: Image.PreserveAspectCrop
cache: false
asynchronous: true
@@ -130,7 +130,7 @@ StyledRect {
sourceComponent: StyledRect {
radius: Appearance.rounding.full
- color: root.modelData.urgency === NotificationUrgency.Critical ? Colours.palette.m3error : root.modelData.urgency === NotificationUrgency.Low ? Colours.palette.m3surfaceContainerHighest : Colours.palette.m3tertiaryContainer
+ color: root.modelData?.urgency === NotificationUrgency.Critical ? Colours.palette.m3error : root.modelData?.urgency === NotificationUrgency.Low ? Colours.palette.m3surfaceContainerHighest : Colours.palette.m3tertiaryContainer
implicitWidth: root.hasImage ? NotifsConfig.sizes.badge : NotifsConfig.sizes.image
implicitHeight: root.hasImage ? NotifsConfig.sizes.badge : NotifsConfig.sizes.image
@@ -141,26 +141,26 @@ StyledRect {
asynchronous: true
anchors.centerIn: parent
- visible: !root.modelData.appIcon.includes("symbolic")
+ visible: !root.modelData?.appIcon.includes("symbolic")
width: Math.round(parent.width * 0.6)
height: Math.round(parent.width * 0.6)
sourceComponent: IconImage {
implicitSize: Math.round(parent.width * 0.6)
- source: Quickshell.iconPath(root.modelData.appIcon)
+ source: Quickshell.iconPath(root.modelData?.appIcon)
asynchronous: true
}
}
Loader {
- active: root.modelData.appIcon.includes("symbolic")
+ active: root.modelData?.appIcon.includes("symbolic") ?? false
asynchronous: true
anchors.fill: icon
sourceComponent: Colouriser {
source: icon
- colorizationColor: root.modelData.urgency === NotificationUrgency.Critical ? Colours.palette.m3onError : root.modelData.urgency === NotificationUrgency.Low ? Colours.palette.m3onSurface : Colours.palette.m3onTertiaryContainer
+ colorizationColor: root.modelData?.urgency === NotificationUrgency.Critical ? Colours.palette.m3onError : root.modelData?.urgency === NotificationUrgency.Low ? Colours.palette.m3onSurface : Colours.palette.m3onTertiaryContainer
}
}
@@ -171,7 +171,7 @@ StyledRect {
sourceComponent: MaterialIcon {
text: {
- const summary = root.modelData.summary.toLowerCase();
+ const summary = root.modelData?.summary.toLowerCase() ?? "";
if (summary.includes("reboot"))
return "restart_alt";
if (summary.includes("recording"))
@@ -190,12 +190,12 @@ StyledRect {
return "update";
if (summary.startsWith("file"))
return "folder_copy";
- if (root.modelData.urgency === NotificationUrgency.Critical)
+ if (root.modelData?.urgency === NotificationUrgency.Critical)
return "release_alert";
return "chat";
}
- color: root.modelData.urgency === NotificationUrgency.Critical ? Colours.palette.m3onError : root.modelData.urgency === NotificationUrgency.Low ? Colours.palette.m3onSurface : Colours.palette.m3onTertiaryContainer
+ color: root.modelData?.urgency === NotificationUrgency.Critical ? Colours.palette.m3onError : root.modelData?.urgency === NotificationUrgency.Low ? Colours.palette.m3onSurface : Colours.palette.m3onTertiaryContainer
font.pointSize: Appearance.font.size.large
}
}
@@ -225,7 +225,7 @@ StyledRect {
TextMetrics {
id: appNameMetrics
- text: root.modelData.appName
+ text: root.modelData?.appName ?? ""
font.family: appName.font.family
font.pointSize: appName.font.pointSize
elide: Text.ElideRight
@@ -278,7 +278,7 @@ StyledRect {
TextMetrics {
id: summaryMetrics
- text: root.modelData.summary
+ text: root.modelData?.summary ?? ""
font.family: summary.font.family
font.pointSize: summary.font.pointSize
elide: Text.ElideRight
@@ -324,7 +324,7 @@ StyledRect {
animate: true
horizontalAlignment: Text.AlignLeft
- text: root.modelData.timeStr
+ text: root.modelData?.timeStr ?? ""
color: Colours.palette.m3onSurfaceVariant
font.pointSize: Appearance.font.size.small
}
@@ -381,7 +381,7 @@ StyledRect {
TextMetrics {
id: bodyPreviewMetrics
- text: root.modelData.body
+ text: root.modelData?.body ?? ""
font.family: bodyPreview.font.family
font.pointSize: bodyPreview.font.pointSize
elide: Text.ElideRight
@@ -398,7 +398,7 @@ StyledRect {
animate: true
textFormat: Text.MarkdownText
- text: root.modelData.body
+ text: root.modelData?.body ?? ""
color: Colours.palette.m3onSurfaceVariant
font.pointSize: Appearance.font.size.small
wrapMode: Text.WrapAtWordBoundaryOrAnywhere
@@ -426,7 +426,7 @@ StyledRect {
}
Repeater {
- model: root.modelData.actions
+ model: root.modelData?.actions ?? 0
delegate: StyledRect {
id: action
@@ -445,7 +445,7 @@ StyledRect {
radius: Appearance.rounding.full
function onClicked(): void {
- action.modelData.invoke();
+ action.modelData?.invoke();
}
}
@@ -461,12 +461,12 @@ StyledRect {
TextMetrics {
id: actionTextMetrics
- text: modelData.text
+ text: modelData?.text
font.family: actionText.font.family
font.pointSize: actionText.font.pointSize
elide: Text.ElideRight
elideWidth: {
- const numActions = root.modelData.actions.length;
+ const numActions = root.modelData?.actions.length;
return (inner.width - actions.spacing * (numActions - 1)) / numActions - Appearance.padding.normal * 2;
}
}