Skip to content

Commit

Permalink
load types installed at runtime
Browse files Browse the repository at this point in the history
closes #938
  • Loading branch information
Steve-Mcl committed Sep 21, 2024
1 parent 3ae153b commit 81b7f23
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions nodes/config/ui_base.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ module.exports = function (RED) {
*/

uiShared.contribs = loadContribs(node)
node.onTypeRegistered = onTypeRegistered.bind(null, node)
RED.events.on('type-registered', node.onTypeRegistered)

/**
* Configure Web Server to handle UI traffic
Expand Down Expand Up @@ -188,6 +190,20 @@ module.exports = function (RED) {
}
}

function onTypeRegistered (node, type) {
// reload nodes from user directory package.json
if (RED.settings?.userDir) {
try {
const contribs = getThirdPartyWidgets(RED.settings.userDir)
if (contribs[type]) {
uiShared.contribs[type] = contribs[type]
}
} catch (error) {
node.log('Cannot import third party widget for type ' + type)
}
}
}

function loadContribs (node) {
// from nodesDir
let contribs = { ...uiShared.contribs }
Expand Down Expand Up @@ -273,6 +289,7 @@ module.exports = function (RED) {
}
node.ui.dashboards.clear() // ensure we clear out any dashboards that may have been left over
node.uiShared = null // remove reference to ui object
RED.events.off('type-registered', node.onTypeRegistered)
done && done()
}

Expand Down

0 comments on commit 81b7f23

Please sign in to comment.