feat(notifs): handle transient notifications properly
Transient notifications are not persistently shown in the dashboard, and thus permanently expire after their timer runs out.
This commit is contained in:
parent
3bb5e10d4d
commit
a9dab6189d
3 changed files with 22 additions and 17 deletions
|
|
@ -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<Notifs.Notif> 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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue