From 1a5dbfb5ec74156f556ffbcab7e772fa6b6142ba Mon Sep 17 00:00:00 2001 From: Ruben Daniels Date: Fri, 24 Apr 2015 00:34:07 +0000 Subject: [PATCH] Loads the package browser in the IDE and many tweaks --- plugins/c9.ide.plugins/installer.js | 73 +++++++++++++++-------------- plugins/c9.ide.plugins/packages.js | 17 ++----- 2 files changed, 43 insertions(+), 47 deletions(-) diff --git a/plugins/c9.ide.plugins/installer.js b/plugins/c9.ide.plugins/installer.js index 2e102bae..754788c0 100644 --- a/plugins/c9.ide.plugins/installer.js +++ b/plugins/c9.ide.plugins/installer.js @@ -13,6 +13,8 @@ define(function(require, exports, module) { var auth = imports.auth; var pubsub = imports.pubsub; + var async = require("async"); + var escapeShell = util.escapeShell; var updates = options.updates; var architect; @@ -20,11 +22,10 @@ define(function(require, exports, module) { /***** Initialization *****/ var plugin = new Plugin("Ajax.org", main.consumes); - // var emit = plugin.getEmitter(); + var emit = plugin.getEmitter(); var HASSDK = c9.location.indexOf("sdk=0") === -1; - var queue = []; var installing; var loaded = false; @@ -69,38 +70,40 @@ define(function(require, exports, module) { // return; // } - if (!config.length) return; + if (!config.length) + return callback && callback(); - var found = {}; - config.forEach(function(item){ - if (!found[item.packageName]) - found[item.packageName] = true; - else return; - - queue.push({ name: item.packageName, version: item.version }); - - if (installing) - installing.push(item); - }); - - if (installing) return; - installing = config; - - var i = 0; - function next(err){ - if (err) console.log(err); - - if (!queue[i]) { - installing = false; queue = []; - architect.loadAdditionalPlugins(config, callback); - return; - } - - installPlugin(queue[i].name, queue[i].version, next); - i++; + // Only run one installer at a time + if (installing) { + return plugin.once("finished", function(){ + installPlugins(config, callback); + }); } - next(); + installing = true; + + var found = {}, packages = []; + config.forEach(function(item){ + if (!found[item.name]) + found[item.name] = true; + else return; + + packages.push({ name: item.name, version: item.version }); + }); + + async.eachSeries(packages, function(pkg, next){ + installPlugin(pkg.name, pkg.version, next); + }, function(err){ + installing = false; + emit("finished"); + + if (err) { + console.error(err.message); + return callback && callback(err); + } + + architect.loadAdditionalPlugins(config, callback); + }); } function installPlugin(name, version, callback){ @@ -109,16 +112,17 @@ define(function(require, exports, module) { }, function(err, process){ if (err) return callback(err); + var output = ""; process.stdout.on("data", function(c){ - console.log(c); + output += c; }); process.stderr.on("data", function(c){ - console.error(c); + output += c; }); process.on("exit", function(code){ if (code) { - var error = new Error(err); + var error = new Error(output); error.code = code; return callback(error); } @@ -160,7 +164,6 @@ define(function(require, exports, module) { plugin.on("unload", function() { loaded = false; installing = false; - queue = []; }); /***** Register and define API *****/ diff --git a/plugins/c9.ide.plugins/packages.js b/plugins/c9.ide.plugins/packages.js index dd56ff87..4b466aef 100644 --- a/plugins/c9.ide.plugins/packages.js +++ b/plugins/c9.ide.plugins/packages.js @@ -137,15 +137,15 @@ define(function(require, exports, module) { tab = e.tab; var htmlNode = e.htmlNode; + htmlNode.style.paddingTop = 0; + iframe = htmlNode.appendChild(document.createElement("iframe")); - iframe.style.position = "absolute"; - iframe.style.top = 0; - iframe.style.left = 0; iframe.style.width = "100%"; iframe.style.height = "100%"; iframe.style.border = 0; + iframe.style.backgroundColor = "#fbfbfb"; - iframe.src = location.origin + "/profile/packages?nobar=1&pid=" + c9.projectId; + iframe.src = location.origin.replace("ide.", "") + "/profile/packages?nobar=1&pid=" + c9.projectId; }); plugin.on("getState", function(e) { @@ -160,7 +160,7 @@ define(function(require, exports, module) { doc.title = "Package Browser"; function setTheme(){ - var bg = "#ededed"; + var bg = "#fbfbfb"; doc.tab.backgroundColor = bg; if (util.shadeColor(bg, 1).isLight) @@ -174,14 +174,7 @@ define(function(require, exports, module) { }); plugin.on("documentActivate", function(e) { - e.doc.tab.on("unload", function(){ - if (parent.parentNode == tab) - tab.removeChild(parent); - }); - tab.appendChild(parent); - - emit("show"); }); /***** Register and define API *****/