Skip to content

Commit 21eb417

Browse files
committed
Add onEmitConfig hook for plugins
1 parent b38ee97 commit 21eb417

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

nodes/config/ui_base.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -473,16 +473,31 @@ module.exports = function (RED) {
473473
if (!handshakeEditKey || !meta?.wysiwyg?.editKey || handshakeEditKey !== meta.wysiwyg.editKey) {
474474
delete meta.wysiwyg
475475
}
476-
// pass the connected UI the UI config
477-
socket.emit('ui-config', node.id, {
476+
477+
// Prepare the UI configuration
478+
const uiConfig = {
478479
meta,
479480
dashboards: Object.fromEntries(node.ui.dashboards),
480481
heads: Object.fromEntries(node.ui.heads),
481482
pages: Object.fromEntries(node.ui.pages),
482483
themes: Object.fromEntries(node.ui.themes),
483484
groups: Object.fromEntries(node.ui.groups),
484485
widgets: Object.fromEntries(node.ui.widgets)
486+
}
487+
488+
// Apply plugin modifications
489+
let finalConfig = uiConfig
490+
RED.plugins.getByType('node-red-dashboard-2').forEach(plugin => {
491+
if (plugin.hooks?.onEmitConfig) {
492+
const modifiedConfig = plugin.hooks.onEmitConfig(socket, finalConfig)
493+
if (modifiedConfig) {
494+
finalConfig = modifiedConfig
495+
}
496+
}
485497
})
498+
499+
// Pass the connected UI the UI config
500+
socket.emit('ui-config', node.id, finalConfig)
486501
}
487502

488503
// remove event handler socket listeners for a given socket connection

0 commit comments

Comments
 (0)