Skip to content

Commit

Permalink
Configurable Connection Notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
cgjgh committed Nov 20, 2024
1 parent 75c7e62 commit 7070f21
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 12 deletions.
6 changes: 5 additions & 1 deletion nodes/config/locales/en-US/ui_base.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@
"navigationStyleFixed": "Fixed",
"navigationStyleIcon": "Collapse to icons",
"navigationStyleTemporary": "Appear over content",
"navigationStyleNone": "Always hide"
"navigationStyleNone": "Always hide",
"notifications": "Notifications",
"showReconnect": "Show reconnect notification",
"showDisconnect": "Show disconnect notification",
"reconnectNotificationDelay": "Reconnect notification delay (s)"
},
"layout": {
"pages": "Pages",
Expand Down
39 changes: 39 additions & 0 deletions nodes/config/ui_base.html
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,15 @@
},
titleBarStyle: {
value: 'default'
},
showReconnectNotification: {
value: true
},
reconnectNotificationDelay: {
value: 2
},
showDisconnectNotification: {
value: true
}
},
label: function () {
Expand All @@ -372,6 +381,20 @@
if (this.appIcon) {
$('#node-config-input-appIcon').val(this.appIcon)
}

if (!this.showReconnectNotification) {
this.showReconnectNotification = true
$('#node-config-input-showReconnectNotification').prop('checked', true)
}

if (!this.reconnectNotificationDelay) {
this.reconnectNotificationDelay = 2
$('#node-config-input-reconnectNotificationDelay').val(this.reconnectNotificationDelay)
}
if (!this.showDisconnectNotification) {
this.showDisconnectNotification = true
$('#node-config-input-showDisconnectNotification').prop('checked', true)
}
},
onpaletteadd: function () {
// add the Dashboard 2.0 sidebar
Expand Down Expand Up @@ -2429,4 +2452,20 @@
<input style="margin: 8px 0 10px 16px; width:20px;" type="checkbox" id="node-config-input-showPathInSidebar">
<label style="width:auto" for="node-config-input-showPathInSidebar"><span data-i18n="ui-base.label.showPath"></span></label>
</div>
<div class="form-row" style="margin-bottom: 0;">
<label style="font-weight: 600; width: auto;" data-i18n="ui-base.label.notifications"></label>
</div>
<div class="form-row form-row-flex" style="align-items: center;">
<input style="margin: 8px 0 10px 16px; width:20px;" type="checkbox" id="node-config-input-showReconnectNotification">
<label style="width:auto" for="node-config-input-showReconnectNotification"><span data-i18n="ui-base.label.showReconnect"></span></label>
</div>
<div class="form-row form-row-flex" style="align-items: center;">
<input style="width: 80px" type="number" id="node-config-input-reconnectNotificationDelay">
<label style="width:auto" for="node-config-input-reconnectNotificationDelay"><span data-i18n="ui-base.label.reconnectNotificationDelay"></span></label>
</div>

<div class="form-row form-row-flex" style="align-items: center;">
<input style="margin: 8px 0 10px 16px; width:20px;" type="checkbox" id="node-config-input-showDisconnectNotification">
<label style="width:auto" for="node-config-input-showDisconnectNotification"><span data-i18n="ui-base.label.showDisconnect"></span></label>
</div>
</script>
5 changes: 5 additions & 0 deletions ui/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,11 @@ export default {
break
}
}
// store the notification settings in localStorage
const dashboard = payload.dashboards[Object.keys(payload.dashboards)[0]]
localStorage.setItem('ndrb-show-reconnect-notification', JSON.stringify(dashboard.showReconnectNotification))
localStorage.setItem('ndrb-reconnect-notification-delay', JSON.stringify(dashboard.reconnectNotificationDelay))
localStorage.setItem('ndrb-show-disconnect-notification', JSON.stringify(dashboard.showDisconnectNotification))
})
},
methods: {
Expand Down
39 changes: 28 additions & 11 deletions ui/src/main.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@ fetch('_setup')

store.commit('setup/set', setup)

// retrieve the notification settings from localStorage
const showReconnectNotification = JSON.parse(localStorage.getItem('ndrb-show-reconnect-notification')) ?? true
const reconnectNotificationDelay = JSON.parse(localStorage.getItem('ndrb-reconnect-notification-delay')) ?? 2
const showDisconnectNotification = JSON.parse(localStorage.getItem('ndrb-show-disconnect-notification')) ?? true

let disconnected = false
let retryCount = 0 // number of reconnection attempts made

Expand All @@ -157,12 +162,15 @@ fetch('_setup')
retryCount = 0
disconnected = true
}
// tell the user we're trying to connect
Alerts.emit('Connection Lost', 'Attempting to reconnect to server...', 'red', {
displayTime: 0, // displayTime 0 persists notifications until another notification closes it
allowDismiss: false,
showCountdown: false
})

if (showDisconnectNotification) {
// tell the user we're trying to connect
Alerts.emit('Connection Lost', 'Attempting to reconnect to server...', 'red', {
displayTime: 0, // displayTime 0 persists notifications until another notification closes it
allowDismiss: false,
showCountdown: false
})
}
// attempt to reconnect
reconnect()
})
Expand All @@ -171,12 +179,21 @@ fetch('_setup')
console.log('SIO connected')
// if we've just disconnected (i.e. aren't connecting for the first time)
if (disconnected) {
if (showReconnectNotification) {
// send a notification/alert to the user to let them know the connection is live again
Alerts.emit('Connected', 'Connection re-established.', '#1BC318', {
displayTime: 1,
allowDismiss: true,
showCountdown: true
})
Alerts.emit('Connected', 'Connection re-established.', '#1BC318', {
displayTime: reconnectNotificationDelay,
allowDismiss: true,
showCountdown: true
})
} else {
//, send a notification for 1 ms to close the disconnected notification
Alerts.emit('Connected', 'Connection re-established.', '#1BC318', {
displayTime: 0.001, // 1 ms
allowDismiss: false,
showCountdown: false
})
}
}
disconnected = false
clearTimeout(reconnectTO)
Expand Down

0 comments on commit 7070f21

Please sign in to comment.