Skip to content

Commit

Permalink
Rework mock/NotificationsImpl to simplify and compact simulation logic
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeTrahearn-Qinetic committed Jan 16, 2025
1 parent b929b85 commit 945afa7
Showing 1 changed file with 11 additions and 35 deletions.
46 changes: 11 additions & 35 deletions data/mock/NotificationsImpl.qml
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,13 @@ QtObject {
readonly property VeQuickItem _silenceAll: VeQuickItem {
uid: Global.notifications.serviceUid + "/SilenceAll"
onValueChanged: {
for (let i = 0 ; i < notifications.length; ++i) {
const notif = notifications[i]
notif.setSilenced(true)
if(!isNaN(value) && value === 1) {
for (let i = 0 ; i < notifications.length; ++i) {
const notif = notifications[i]
notif.setSilenced(true)
}
_silenceAll.setValue(0)
}
_silenceAll.setValue(0)
}
}

Expand All @@ -145,45 +147,19 @@ QtObject {
notif["_" + p].setValue(value)
}

if (!!params['active']) {
_numberOfActiveNotifications.setValue((_numberOfActiveNotifications.value || 0) + 1)
}

if (params['type'] === VenusOS.Notification_Alarm) {
_numberOfActiveAlarms.setValue((_numberOfActiveAlarms.value || 0 ) + 1)
_numberOfUnsilencedAlarms.setValue((_numberOfUnsilencedAlarms.value || 0 ) + 1)
} else if (params['type'] === VenusOS.Notification_Warning) {
_numberOfActiveWarnings.setValue((_numberOfActiveWarnings.value || 0 ) + 1)
_numberOfUnsilencedWarnings.setValue((_numberOfUnsilencedWarnings.value || 0 ) + 1)
} else if (params['type'] === VenusOS.Notification_Info) {
_numberOfActiveInformations.setValue((_numberOfActiveInformations.value || 0 ) + 1)
_numberOfUnsilencedInformations.setValue((_numberOfUnsilencedInformations.value || 0 ) + 1)
}

notifications.push(notif)
_numberOfNotifications.setValue(notifications.length)

updateNotifications()
}

function removeLastNotification() {
const notif = notifications[notifications.length - 1]
const notificationId = notif.notificationId
if (notif.active) {
_numberOfActiveNotifications.setValue(Math.max(0, _numberOfActiveNotifications.value - 1))
}

if (params['type'] === VenusOS.Notification_Alarm) {
_numberOfActiveAlarms.setValue(Math.max(0, _numberOfActiveAlarms.value - 1))
_numberOfUnsilencedAlarms.setValue(Math.max(0, _numberOfUnsilencedAlarms.value - 1))
} else if (params['type'] === VenusOS.Notification_Warning) {
_numberOfActiveWarnings.setValue(Math.max(0, _numberOfActiveWarnings.value - 1))
_numberOfUnsilencedWarnings.setValue(Math.max(0, _numberOfUnsilencedWarnings.value - 1))
} else if (params['type'] === VenusOS.Notification_Info) {
_numberOfActiveInformations.setValue(Math.max(0, _numberOfActiveInformations.value - 1))
_numberOfUnsilencedInformations.setValue(Math.max(0, _numberOfUnsilencedInformations.value - 1))
}
notifications.splice(notifications.length - 1, 1)

updateNotifications()
notifications.splice(notifications.length - 1, 1)

return notificationId
}

Expand Down Expand Up @@ -220,7 +196,7 @@ QtObject {
}
}
_numberOfActiveNotifications.setValue(activeCount)

_numberOfNotifications.setValue(notifications.length)
_numberOfActiveAlarms.setValue(activeAlarmCount)
_numberOfUnsilencedAlarms.setValue(unsilencedAlarmCount)
_numberOfActiveWarnings.setValue(activeWarningCount)
Expand Down

0 comments on commit 945afa7

Please sign in to comment.