1
0
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:
Nick O'Leary 2014-06-25 10:30:52 +01:00
parent 7c7f030aa8
commit 479a02cc16
2 changed files with 23 additions and 6 deletions

View File

@ -88,8 +88,16 @@ function loadNode(nodeDir, nodeFn, nodeLabel) {
function loadNodesFromModule(moduleDir,pkg) {
var nodes = pkg['node-red'].nodes||{};
var promises = [];
var iconDirs = [];
for (var n in nodes) {
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;
}

View File

@ -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) {
for (var p in icon_paths) {
if (fs.existsSync(icon_paths[p]+'/'+req.params.icon)) {
res.sendfile(icon_paths[p]+'/'+req.params.icon);
return;
if (iconCache[req.params.icon]) {
res.sendfile(iconCache[req.params.icon]);
} else {
for (var p in icon_paths) {
var iconPath = path.join(icon_paths[p],req.params.icon);
if (fs.existsSync(iconPath)) {
res.sendfile(iconPath);
iconCache[req.params.icon] = iconPath;
return;
}
}
res.sendfile(defaultIcon);
}
//TODO: create a default icon
res.sendfile(path.resolve(__dirname + '/../public/icons/arrow-in.png'));
});
app.get("/settings", function(req,res) {