Skip to content

Commit

Permalink
Added Notification.destroy() and comments showing why it doesn't work!
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeTrahearn-Qinetic committed Feb 7, 2025
1 parent 361c1c4 commit 77cae3b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
12 changes: 10 additions & 2 deletions data/Notifications.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -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
Expand All @@ -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")
Expand All @@ -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()
}
}
Expand Down
4 changes: 4 additions & 0 deletions data/common/Notification.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
}
}
9 changes: 9 additions & 0 deletions data/mock/NotificationsImpl.qml
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ QtObject {
let notificationId = numberOfNotifications

if (numberOfNotifications >= maxNotificationCount) {
console.log("IMPL: about to renove")
notificationId = removeLastNotification()
}

Expand All @@ -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
}

Expand Down

0 comments on commit 77cae3b

Please sign in to comment.