diff --git a/data/Notifications.qml b/data/Notifications.qml index 9cbd6d512..7f76fade9 100644 --- a/data/Notifications.qml +++ b/data/Notifications.qml @@ -13,6 +13,11 @@ QtObject { readonly property NotificationsModel allNotificationsModel: NotificationsModel { onNotificationInserted: (notification) => toastedNotification.onNotificationInserted(notification) + // FIXME: the insertion comes before the removal of the "last one" even though the code says otherwise + // - see NotificationsImpl + // We fundamentally have a problem with the way the model is managed. + // The DBUS and MQTT might even remove all notifications before or after recreating them all again! + // onNotificationRemoved is only called after the Notification is destroyed which might be a time after. onNotificationRemoved: (notification) => toastedNotification.onNotificationRemoved(notification) } @@ -27,6 +32,7 @@ QtObject { if(!toastedNotif.toast) { let createdToast = Global.notificationLayer?.showToastNotification(notif.type, "") if(createdToast) { + console.log("Created toast") createdToast.text = Qt.binding(function() { return `${notif.deviceName}\n${notif.description}`}) toastedNotif.toast = createdToast toastedNotif.notification = notif @@ -36,6 +42,7 @@ QtObject { function onNotificationRemoved(notif: BaseNotification) { if(toastedNotif.notification === notif) { + console.log("onNotificationRemoved:close()") close() } else { console.log("notification removed isn't the last one we made a toast for") @@ -50,8 +57,9 @@ QtObject { function checkAndRemoveExistingToast(notif: BaseNotification): bool { if(toast && (notif.type === VenusOS.Notification_Alarm || - (notif.type === VenusOS.Notification_Warning && toast.category !== VenusOS.Notification_Alarm) || - toast.category === VenusOS.Notification_Info)) { + (notif.type === VenusOS.Notification_Warning && toast.category !== VenusOS.Notification_Alarm) || + toast.category === VenusOS.Notification_Info)) { + console.log("checkAndRemoveExistingToast:close()") close() } } diff --git a/data/common/Notification.qml b/data/common/Notification.qml index c7055f624..d0045f185 100644 --- a/data/common/Notification.qml +++ b/data/common/Notification.qml @@ -61,7 +61,9 @@ BaseNotification { return } // insert into the allNotificationsModel + console.log(">>>>>>>>> inserting new") Global.notifications.allNotificationsModel.insertNotification(notification) + console.log("<<<<<<<<< inserting new completed") } // These properties should not be written to; use updateSilenced() and updateActive() functions @@ -76,6 +78,8 @@ BaseNotification { Component.onDestruction: { // remove from the allNotificationsModel + console.log("Notification::onDestruction begin") Global.notifications.allNotificationsModel.removeNotification(notification) + console.log("Notification::onDestruction end") } } diff --git a/data/mock/NotificationsImpl.qml b/data/mock/NotificationsImpl.qml index 16b5e07d3..b6d9eee97 100644 --- a/data/mock/NotificationsImpl.qml +++ b/data/mock/NotificationsImpl.qml @@ -138,6 +138,7 @@ QtObject { let notificationId = numberOfNotifications if (numberOfNotifications >= maxNotificationCount) { + console.log("IMPL: about to renove") notificationId = removeLastNotification() } @@ -156,7 +157,15 @@ QtObject { let notif = notifications.pop() const notificationId = notif.notificationId updateNotifications() + console.log("IMPL: about to destroy") + notif.destroy() // doesn't do it immediately!! + // https://doc.qt.io/qt-6/qtqml-javascript-dynamicobjectcreation.html#deleting-objects-dynamically + // Objects are not destroyed the instant destroy() is called, + // but are cleaned up sometime between the end of that script block + // and the next frame (unless you specified a non-zero delay). + + console.log("IMPL: after destroy") return notificationId }