Add max notification shown, implement queue, fix bug where notifications removed in the server locked the queue
This commit is contained in:
@@ -74,7 +74,7 @@ Item {
|
|||||||
|
|
||||||
onClicked: mouse => {
|
onClicked: mouse => {
|
||||||
if (mouse.button === Qt.RightButton) {
|
if (mouse.button === Qt.RightButton) {
|
||||||
NotificationService.notificationsMuted = !NotificationService.notificationsMuted
|
NotificationService.manualNotificationsMuted = !NotificationService.manualNotificationsMuted
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
root.createWindow = !root.createWindow;
|
root.createWindow = !root.createWindow;
|
||||||
|
|||||||
@@ -8,14 +8,16 @@ import qs.Widgets
|
|||||||
import qs.Services
|
import qs.Services
|
||||||
|
|
||||||
Singleton {
|
Singleton {
|
||||||
id: notificationRoot
|
id: root
|
||||||
|
|
||||||
readonly property var notificationServer: notificationServer
|
readonly property var notificationServer: notificationServer
|
||||||
readonly property var trackedNotifications: notificationServer.trackedNotifications
|
|
||||||
readonly property var notificationsNumber: notificationServer.trackedNotifications.values.length
|
readonly property var notificationsNumber: notificationServer.trackedNotifications.values.length
|
||||||
|
readonly property var maxShown: 3
|
||||||
|
|
||||||
property bool notificationsMuted: HyprlandService.hasFullscreen || HyprlandService.isScreencasting
|
property bool receivingLock: false
|
||||||
property ListModel globalList: ListModel {}
|
property bool manualNotificationsMuted: false
|
||||||
|
property bool notificationsMuted: HyprlandService.hasFullscreen || HyprlandService.isScreencasting || root.manualNotificationsMuted
|
||||||
|
property ListModel trackedNotifications: ListModel {}
|
||||||
|
|
||||||
NotificationServer {
|
NotificationServer {
|
||||||
id: notificationServer
|
id: notificationServer
|
||||||
@@ -25,23 +27,31 @@ Singleton {
|
|||||||
Connections {
|
Connections {
|
||||||
target: notificationServer
|
target: notificationServer
|
||||||
function onNotification(notif) {
|
function onNotification(notif) {
|
||||||
if(notif.transient) return;
|
if(notif.transient || notif.body === "MediaOngoingActivity")
|
||||||
if (notif.body === "MediaOngoingActivity")
|
return;
|
||||||
return;
|
|
||||||
notif.tracked = true;
|
notif.tracked = true;
|
||||||
notificationRoot.addNotification(globalList, notif);
|
root.addNotification(trackedNotifications, notif);
|
||||||
|
|
||||||
if (notif.lastGeneration)
|
if (notif.lastGeneration)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Use the refactored helper
|
// Use the refactored helper
|
||||||
notificationRoot.addNotification(notificationList, notif);
|
if(notificationList.count < root.maxShown && !root.receivingLock ) {
|
||||||
|
root.addNotification(notificationList, notif)
|
||||||
|
} else {
|
||||||
|
root.receivingLock = true
|
||||||
|
root.addNotification(pendingList, notif)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ListModel {
|
ListModel {
|
||||||
id: notificationList
|
id: notificationList
|
||||||
}
|
}
|
||||||
|
ListModel {
|
||||||
|
id: pendingList
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {ListModel} model
|
* @param {ListModel} model
|
||||||
@@ -75,7 +85,7 @@ Singleton {
|
|||||||
// Avoid duplicates
|
// Avoid duplicates
|
||||||
for (let i = 0; i < model.count; i++) {
|
for (let i = 0; i < model.count; i++) {
|
||||||
if (model.get(i).notif === notif)
|
if (model.get(i).notif === notif)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
model.append({
|
model.append({
|
||||||
@@ -87,24 +97,54 @@ Singleton {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// function notificationDismiss(notif) {
|
|
||||||
// removeNotification(notificationList, notif);
|
|
||||||
// removeNotification(globalList, notif);
|
|
||||||
// notif.dismiss();
|
|
||||||
// }
|
|
||||||
|
|
||||||
function notificationDismiss(notif) {
|
function notificationDismiss(notif) {
|
||||||
removeNotification(notificationList, notif);
|
let pendingIdx = -1
|
||||||
removeNotification(globalList, notif);
|
|
||||||
|
for (let i = 0; i < pendingList.count; i++) {
|
||||||
|
if (pendingList.get(i).notif === notif) {
|
||||||
|
pendingIdx = i
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pendingIdx >= 0) {
|
||||||
|
pendingList.remove(pendingIdx, 1)
|
||||||
|
} else {
|
||||||
|
removeNotification(notificationList, notif)
|
||||||
|
}
|
||||||
|
|
||||||
|
removeNotification(trackedNotifications, notif)
|
||||||
|
|
||||||
if (notif && typeof notif.dismiss === "function")
|
if (notif && typeof notif.dismiss === "function")
|
||||||
notif.dismiss(); // dismiss first
|
notif.dismiss()
|
||||||
|
|
||||||
|
tryShowNext()
|
||||||
|
}
|
||||||
|
|
||||||
|
function timeoutNotification(notif) {
|
||||||
|
|
||||||
|
removeNotification(notificationList, notif)
|
||||||
|
|
||||||
|
tryShowNext()
|
||||||
|
}
|
||||||
|
|
||||||
|
function tryShowNext() {
|
||||||
|
let filled = false
|
||||||
|
|
||||||
|
while (notificationList.count < root.maxShown && pendingList.count > 0) {
|
||||||
|
const nextNotif = pendingList.get(0).notif
|
||||||
|
pendingList.remove(0, 1)
|
||||||
|
addNotification(notificationList, nextNotif)
|
||||||
|
filled = true
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only lock if there are still more pending than fit onscreen
|
||||||
|
root.receivingLock = pendingList.count > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
LazyLoader {
|
LazyLoader {
|
||||||
id: popupLoader
|
id: popupLoader
|
||||||
active: notificationList.count && !notificationRoot.notificationsMuted
|
active: notificationList.count && !root.notificationsMuted
|
||||||
|
|
||||||
component: PanelWindow {
|
component: PanelWindow {
|
||||||
id: notificationWindow
|
id: notificationWindow
|
||||||
@@ -136,17 +176,17 @@ Singleton {
|
|||||||
notification: modelData
|
notification: modelData
|
||||||
implicitWidth: listView.width
|
implicitWidth: listView.width
|
||||||
|
|
||||||
|
|
||||||
startTimer: NotificationUrgency.toString(notification?.urgency) === "Critical"? false: true
|
startTimer: NotificationUrgency.toString(notification?.urgency) === "Critical"? false: true
|
||||||
timerDuration: 5000
|
timerDuration: 5000
|
||||||
|
|
||||||
onDismissed: {
|
onDismissed: {
|
||||||
if (notification && typeof notification.dismiss === "function")
|
if (notification && typeof notification.dismiss === "function")
|
||||||
notificationRoot.notificationDismiss(notification);
|
root.notificationDismiss(notification);
|
||||||
}
|
}
|
||||||
|
|
||||||
onTimedout: {
|
onTimedout: {
|
||||||
notificationRoot.removeNotification(notificationList, notification)
|
root.timeoutNotification(notification)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,8 +21,6 @@ PopupWindow {
|
|||||||
visible: true
|
visible: true
|
||||||
signal clear
|
signal clear
|
||||||
|
|
||||||
mask: Region { item: listView }
|
|
||||||
|
|
||||||
MouseArea {
|
MouseArea {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
onClicked: notificationRoot.clear()
|
onClicked: notificationRoot.clear()
|
||||||
@@ -57,7 +55,7 @@ PopupWindow {
|
|||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
onClicked: {
|
onClicked: {
|
||||||
while (NotificationService.notificationsNumber != 0) {
|
while (NotificationService.notificationsNumber != 0) {
|
||||||
NotificationService.trackedNotifications.values[0].dismiss();
|
NotificationService.notificationDismiss(NotificationService.trackedNotifications.get(0).notif)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -71,7 +69,7 @@ PopupWindow {
|
|||||||
id: listView
|
id: listView
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
Layout.fillHeight: true
|
Layout.fillHeight: true
|
||||||
model: NotificationService.globalList
|
model: NotificationService.trackedNotifications
|
||||||
clip: true
|
clip: true
|
||||||
spacing: 5
|
spacing: 5
|
||||||
leftMargin: 10
|
leftMargin: 10
|
||||||
|
|||||||
Reference in New Issue
Block a user