mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Enable npm nodes to provide custom icons
This commit is contained in:
parent
7c7f030aa8
commit
479a02cc16
@ -88,8 +88,16 @@ function loadNode(nodeDir, nodeFn, nodeLabel) {
|
|||||||
function loadNodesFromModule(moduleDir,pkg) {
|
function loadNodesFromModule(moduleDir,pkg) {
|
||||||
var nodes = pkg['node-red'].nodes||{};
|
var nodes = pkg['node-red'].nodes||{};
|
||||||
var promises = [];
|
var promises = [];
|
||||||
|
var iconDirs = [];
|
||||||
for (var n in nodes) {
|
for (var n in nodes) {
|
||||||
promises.push(loadNode(moduleDir,nodes[n],pkg.name+":"+n));
|
promises.push(loadNode(moduleDir,nodes[n],pkg.name+":"+n));
|
||||||
|
var iconDir = path.join(moduleDir,path.dirname(nodes[n]),"icons");
|
||||||
|
if (iconDirs.indexOf(iconDir) == -1) {
|
||||||
|
if (fs.existsSync(iconDir)) {
|
||||||
|
events.emit("node-icon-dir",iconDir);
|
||||||
|
iconDirs.push(iconDir);
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return promises;
|
return promises;
|
||||||
}
|
}
|
||||||
|
17
red/ui.js
17
red/ui.js
@ -41,15 +41,24 @@ function setupUI(settings) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var iconCache = {};
|
||||||
|
//TODO: create a default icon
|
||||||
|
var defaultIcon = path.resolve(__dirname + '/../public/icons/arrow-in.png');
|
||||||
|
|
||||||
app.get("/icons/:icon",function(req,res) {
|
app.get("/icons/:icon",function(req,res) {
|
||||||
|
if (iconCache[req.params.icon]) {
|
||||||
|
res.sendfile(iconCache[req.params.icon]);
|
||||||
|
} else {
|
||||||
for (var p in icon_paths) {
|
for (var p in icon_paths) {
|
||||||
if (fs.existsSync(icon_paths[p]+'/'+req.params.icon)) {
|
var iconPath = path.join(icon_paths[p],req.params.icon);
|
||||||
res.sendfile(icon_paths[p]+'/'+req.params.icon);
|
if (fs.existsSync(iconPath)) {
|
||||||
|
res.sendfile(iconPath);
|
||||||
|
iconCache[req.params.icon] = iconPath;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//TODO: create a default icon
|
res.sendfile(defaultIcon);
|
||||||
res.sendfile(path.resolve(__dirname + '/../public/icons/arrow-in.png'));
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
app.get("/settings", function(req,res) {
|
app.get("/settings", function(req,res) {
|
||||||
|
Loading…
Reference in New Issue
Block a user