diff --git a/modules/dashboard/dash/Notifs.qml b/modules/dashboard/dash/Notifs.qml index 81362eb..59d2b09 100644 --- a/modules/dashboard/dash/Notifs.qml +++ b/modules/dashboard/dash/Notifs.qml @@ -17,9 +17,7 @@ ColumnLayout { spacing: 7 - readonly property int notifCount: - (Notifs.list && Notifs.list.length !== undefined) ? Notifs.list.length : - ((Notifs.list && Notifs.list.count !== undefined) ? Notifs.list.count : 0) + readonly property list list: Notifs.list.filter(n => !n.notification.transient) function notifAt(i) { if (!Notifs.list) @@ -47,14 +45,14 @@ ColumnLayout { text: { if (Notifs.dnd) return "notifications_off"; - if (notifCount > 0) + if (root.list.length > 0) return "notifications_active"; return "notifications"; } fill: { if (Notifs.dnd) return 0; - if (notifCount > 0) + if (root.list.length > 0) return 1; return 0; } @@ -75,7 +73,7 @@ ColumnLayout { CustomText { Layout.alignment: Qt.AlignVCenter Layout.fillWidth: true - text: notifCount > 0 ? qsTr("%1 notifications").arg(notifCount) : qsTr("No notifications") + text: root.list.length > 0 ? qsTr("%1 notifications").arg(root.list.length) : qsTr("No notifications") font.weight: 600 font.pointSize: Config.font.size.normal animate: true @@ -117,7 +115,7 @@ ColumnLayout { } model: ScriptModel { - values: [...Notifs.list].reverse() + values: [...root.list].reverse() } delegate: Item { @@ -209,8 +207,8 @@ ColumnLayout { anchors.bottom: parent.bottom anchors.bottomMargin: bottomMargin - property real bottomMargin: notifCount > 0 ? 12 : -4 - opacity: notifCount > 0 ? 1 : 0 + property real bottomMargin: root.list.length > 0 ? 12 : -4 + opacity: root.list.length > 0 ? 1 : 0 visible: opacity > 0 implicitWidth: clearBtn.implicitWidth + 32 implicitHeight: clearBtn.implicitHeight + 20 @@ -230,7 +228,7 @@ ColumnLayout { anchors.fill: parent function onClicked(): void { - for (let i = root.notifCount - 1; i >= 0; i--) { + for (let i = root.list.length - 1; i >= 0; i--) { const n = root.notifAt(i); n?.notification?.dismiss(); } diff --git a/modules/notifications/Notification.qml b/modules/notifications/Notification.qml index dd9dc91..47516e2 100644 --- a/modules/notifications/Notification.qml +++ b/modules/notifications/Notification.qml @@ -76,7 +76,7 @@ CustomRect { if (Math.abs(root.x) < Config.notifs.width * Config.notifs.clearThreshold) root.x = 0; else if (root.inPopup) - root.notif.popup = null; + root.notif.clear(); else root.notif.notification.dismiss(); } diff --git a/services/Notifs.qml b/services/Notifs.qml index decc95e..016186d 100644 --- a/services/Notifs.qml +++ b/services/Notifs.qml @@ -45,7 +45,7 @@ Singleton { description: "Clear all notifications" onPressed: { for (const notif of root.list) - notif.popup = null; + notif.clear(); } } @@ -93,13 +93,20 @@ Singleton { // One-line version (for non-expanded notifications) readonly property string bodyOneLine: notification.body.replace("\n", " ") + readonly property int expireTimeout: notification.expireTimeout > 0 ? + notification.expireTimeout : Config.notifs.defaultExpireTimeout + readonly property Timer timer: Timer { running: true - interval: notif.notification.expireTimeout > 0 ? notif.notification.expireTimeout : Config.notifs.defaultExpireTimeout - onTriggered: { - if (Config.notifs.expire) - notif.popup = null; - } + interval: notif.expireTimeout + onTriggered: notif.clear() + } + + function clear(): void { + if (notification.transient) + notification.expire(); + else + popup = null; } readonly property Connections conn: Connections {