From 324b9b1f5f20c7b602ebe39650ac38ecc7768fc4 Mon Sep 17 00:00:00 2001 From: Marcel Klehr Date: Mon, 8 Apr 2013 16:14:03 +0200 Subject: [PATCH] pluginfw/installer: Only restart the server when all tasks have finished fixes #1685 --- src/static/js/pluginfw/installer.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/static/js/pluginfw/installer.js b/src/static/js/pluginfw/installer.js index 377be35e9..22e643508 100644 --- a/src/static/js/pluginfw/installer.js +++ b/src/static/js/pluginfw/installer.js @@ -15,7 +15,21 @@ var withNpm = function (npmfn) { }); } +var tasks = 0 +function wrapTaskCb(cb) { + tasks++ + return function() { + cb && cb.apply(this, arguments); + tasks--; + if(tasks == 0) onAllTasksFinished(); + } +} +function onAllTasksFinished() { + hooks.aCallAll("restartServer", {}, function () {}); +} + exports.uninstall = function(plugin_name, cb) { + cb = wrapTaskCb(cb); withNpm(function (er) { if (er) return cb && cb(er); npm.commands.uninstall([plugin_name], function (er) { @@ -23,13 +37,13 @@ exports.uninstall = function(plugin_name, cb) { hooks.aCallAll("pluginUninstall", {plugin_name: plugin_name}, function (er, data) { if (er) return cb(er); plugins.update(cb); - hooks.aCallAll("restartServer", {}, function () {}); }); }); }); }; exports.install = function(plugin_name, cb) { + cb = wrapTaskCb(cb) withNpm(function (er) { if (er) return cb && cb(er); npm.commands.install([plugin_name], function (er) { @@ -37,7 +51,6 @@ exports.install = function(plugin_name, cb) { hooks.aCallAll("pluginInstall", {plugin_name: plugin_name}, function (er, data) { if (er) return cb(er); plugins.update(cb); - hooks.aCallAll("restartServer", {}, function () {}); }); }); });