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
|
spacing: 7
|
||||||
|
|
||||||
readonly property int notifCount:
|
readonly property list<Notifs.Notif> list: Notifs.list.filter(n => !n.notification.transient)
|
||||||
(Notifs.list && Notifs.list.length !== undefined) ? Notifs.list.length :
|
|
||||||
((Notifs.list && Notifs.list.count !== undefined) ? Notifs.list.count : 0)
|
|
||||||
|
|
||||||
function notifAt(i) {
|
function notifAt(i) {
|
||||||
if (!Notifs.list)
|
if (!Notifs.list)
|
||||||
|
|
@ -47,14 +45,14 @@ ColumnLayout {
|
||||||
text: {
|
text: {
|
||||||
if (Notifs.dnd)
|
if (Notifs.dnd)
|
||||||
return "notifications_off";
|
return "notifications_off";
|
||||||
if (notifCount > 0)
|
if (root.list.length > 0)
|
||||||
return "notifications_active";
|
return "notifications_active";
|
||||||
return "notifications";
|
return "notifications";
|
||||||
}
|
}
|
||||||
fill: {
|
fill: {
|
||||||
if (Notifs.dnd)
|
if (Notifs.dnd)
|
||||||
return 0;
|
return 0;
|
||||||
if (notifCount > 0)
|
if (root.list.length > 0)
|
||||||
return 1;
|
return 1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -75,7 +73,7 @@ ColumnLayout {
|
||||||
CustomText {
|
CustomText {
|
||||||
Layout.alignment: Qt.AlignVCenter
|
Layout.alignment: Qt.AlignVCenter
|
||||||
Layout.fillWidth: true
|
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.weight: 600
|
||||||
font.pointSize: Config.font.size.normal
|
font.pointSize: Config.font.size.normal
|
||||||
animate: true
|
animate: true
|
||||||
|
|
@ -117,7 +115,7 @@ ColumnLayout {
|
||||||
}
|
}
|
||||||
|
|
||||||
model: ScriptModel {
|
model: ScriptModel {
|
||||||
values: [...Notifs.list].reverse()
|
values: [...root.list].reverse()
|
||||||
}
|
}
|
||||||
|
|
||||||
delegate: Item {
|
delegate: Item {
|
||||||
|
|
@ -209,8 +207,8 @@ ColumnLayout {
|
||||||
anchors.bottom: parent.bottom
|
anchors.bottom: parent.bottom
|
||||||
anchors.bottomMargin: bottomMargin
|
anchors.bottomMargin: bottomMargin
|
||||||
|
|
||||||
property real bottomMargin: notifCount > 0 ? 12 : -4
|
property real bottomMargin: root.list.length > 0 ? 12 : -4
|
||||||
opacity: notifCount > 0 ? 1 : 0
|
opacity: root.list.length > 0 ? 1 : 0
|
||||||
visible: opacity > 0
|
visible: opacity > 0
|
||||||
implicitWidth: clearBtn.implicitWidth + 32
|
implicitWidth: clearBtn.implicitWidth + 32
|
||||||
implicitHeight: clearBtn.implicitHeight + 20
|
implicitHeight: clearBtn.implicitHeight + 20
|
||||||
|
|
@ -230,7 +228,7 @@ ColumnLayout {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
|
|
||||||
function onClicked(): void {
|
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);
|
const n = root.notifAt(i);
|
||||||
n?.notification?.dismiss();
|
n?.notification?.dismiss();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -76,7 +76,7 @@ CustomRect {
|
||||||
if (Math.abs(root.x) < Config.notifs.width * Config.notifs.clearThreshold)
|
if (Math.abs(root.x) < Config.notifs.width * Config.notifs.clearThreshold)
|
||||||
root.x = 0;
|
root.x = 0;
|
||||||
else if (root.inPopup)
|
else if (root.inPopup)
|
||||||
root.notif.popup = null;
|
root.notif.clear();
|
||||||
else
|
else
|
||||||
root.notif.notification.dismiss();
|
root.notif.notification.dismiss();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,7 @@ Singleton {
|
||||||
description: "Clear all notifications"
|
description: "Clear all notifications"
|
||||||
onPressed: {
|
onPressed: {
|
||||||
for (const notif of root.list)
|
for (const notif of root.list)
|
||||||
notif.popup = null;
|
notif.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -93,13 +93,20 @@ Singleton {
|
||||||
// One-line version (for non-expanded notifications)
|
// One-line version (for non-expanded notifications)
|
||||||
readonly property string bodyOneLine: notification.body.replace("\n", " ")
|
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 {
|
readonly property Timer timer: Timer {
|
||||||
running: true
|
running: true
|
||||||
interval: notif.notification.expireTimeout > 0 ? notif.notification.expireTimeout : Config.notifs.defaultExpireTimeout
|
interval: notif.expireTimeout
|
||||||
onTriggered: {
|
onTriggered: notif.clear()
|
||||||
if (Config.notifs.expire)
|
}
|
||||||
notif.popup = null;
|
|
||||||
}
|
function clear(): void {
|
||||||
|
if (notification.transient)
|
||||||
|
notification.expire();
|
||||||
|
else
|
||||||
|
popup = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
readonly property Connections conn: Connections {
|
readonly property Connections conn: Connections {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue