From 7c29cc57f100bce146698c1d33f577f2aa09b197 Mon Sep 17 00:00:00 2001 From: Nitesh Kumar <38075523+niteskum@users.noreply.github.com> Date: Tue, 24 Jul 2018 13:29:15 +0530 Subject: [PATCH] Auto Update Error Handlng Fix (#14412) * Auto Update Error Handlng Fix * Addressed Review comments --- .../default/AutoUpdate/MessageIds.js | 2 +- src/extensions/default/AutoUpdate/main.js | 39 ++++++++++--------- .../AutoUpdate/node/AutoUpdateDomain.js | 4 +- 3 files changed, 24 insertions(+), 21 deletions(-) diff --git a/src/extensions/default/AutoUpdate/MessageIds.js b/src/extensions/default/AutoUpdate/MessageIds.js index b969aab6150..464ddf48836 100644 --- a/src/extensions/default/AutoUpdate/MessageIds.js +++ b/src/extensions/default/AutoUpdate/MessageIds.js @@ -38,6 +38,6 @@ define(function (require, exports, module) { exports.NOTIFY_INITIALIZATION_COMPLETE = "brackets.notifyinitializationComplete"; exports.NOTIFY_VALIDATION_STATUS = "brackets.notifyvalidationStatus"; exports.NOTIFY_INSTALLATION_STATUS = "brackets.notifyInstallationStatus"; - exports.SET_UPDATE_IN_PROGRESS_STATE = "brackets.setAutoUpdateInProgress"; + exports.NODE_DOMAIN_INITIALIZED = "brackets.nodeDomainInitialized"; exports.REGISTER_BRACKETS_FUNCTIONS = "brackets.registerBracketsFunctions"; }); diff --git a/src/extensions/default/AutoUpdate/main.js b/src/extensions/default/AutoUpdate/main.js index 1a36c486178..da8eff67c4b 100644 --- a/src/extensions/default/AutoUpdate/main.js +++ b/src/extensions/default/AutoUpdate/main.js @@ -223,6 +223,7 @@ define(function (require, exports, module) { if (downloadCompleted && updateInitiatedInPrevSession) { var isNewVersion = checkIfVersionUpdated(); + updateJsonHandler.reset(); if (isNewVersion) { // We get here if the update was successful UpdateInfoBar.showUpdateBar({ @@ -280,19 +281,14 @@ define(function (require, exports, module) { /** * Initializes the state of parsed content from updateHelper.json + * returns Promise Object Which is resolved when parsing is success + * and rejected if parsing is failed. */ function initState() { + var result = $.Deferred(); updateJsonHandler.parse() .done(function() { - checkIfAnotherSessionInProgress() - .done(function (inProgress) { - if (!inProgress) { - checkUpdateStatus(); - } - }) - .fail(function () { - checkUpdateStatus(); - }); + result.resolve(); }) .fail(function (code) { var logMsg; @@ -311,7 +307,9 @@ define(function (require, exports, module) { break; } console.log(logMsg); + result.reject(); }); + return result.promise(); } @@ -321,15 +319,13 @@ define(function (require, exports, module) { */ function setupAutoUpdate() { updateJsonHandler = new StateHandler(updateJsonPath); + updateDomain.on('data', receiveMessageFromNode); updateDomain.exec('initNode', { messageIds: MessageIds, updateDir: updateDir, requester: domainID }); - - updateDomain.on('data', receiveMessageFromNode); - initState(); } @@ -594,11 +590,17 @@ define(function (require, exports, module) { /** * Enables/disables the state of "Auto Update In Progress" in UpdateHandler.json */ - function setAutoUpdateInProgressFlag(flag) { - updateJsonHandler.parse() - .done(function() { - setUpdateStateInJSON("autoUpdateInProgress", flag); - }); + function nodeDomainInitialized(reset) { + initState() + .done(function () { + var inProgress = updateJsonHandler.get(updateProgressKey); + if (inProgress && reset) { + setUpdateStateInJSON(updateProgressKey, !reset) + .always(checkUpdateStatus); + } else if (!inProgress) { + checkUpdateStatus(); + } + }); } @@ -636,7 +638,6 @@ define(function (require, exports, module) { enableCheckForUpdateEntry(true); console.error(message); - setUpdateStateInJSON("autoUpdateInProgress", false); } /** @@ -1124,7 +1125,7 @@ define(function (require, exports, module) { ProjectManager.on("beforeProjectClose beforeAppClose", _handleAppClose); } - functionMap["brackets.setAutoUpdateInProgress"] = setAutoUpdateInProgressFlag; + functionMap["brackets.nodeDomainInitialized"] = nodeDomainInitialized; functionMap["brackets.registerBracketsFunctions"] = registerBracketsFunctions; }); diff --git a/src/extensions/default/AutoUpdate/node/AutoUpdateDomain.js b/src/extensions/default/AutoUpdate/node/AutoUpdateDomain.js index 9e635d8f1b1..2f63ee3d7e7 100644 --- a/src/extensions/default/AutoUpdate/node/AutoUpdateDomain.js +++ b/src/extensions/default/AutoUpdate/node/AutoUpdateDomain.js @@ -419,6 +419,7 @@ * requester : ID of the current requester domain} */ function initNode(initObj) { + var resetUpdateProgres = false; if (!isNodeDomainInitialized) { MessageIds = initObj.messageIds; updateDir = path.resolve(initObj.updateDir); @@ -426,8 +427,9 @@ installStatusFilePath = path.resolve(updateDir, installStatusFile); registerNodeFunctions(); isNodeDomainInitialized = true; - postMessageToBrackets(MessageIds.SET_UPDATE_IN_PROGRESS_STATE, initObj.requester.toString(), false); + resetUpdateProgres = true; } + postMessageToBrackets(MessageIds.NODE_DOMAIN_INITIALIZED, initObj.requester.toString(), resetUpdateProgres); requesters[initObj.requester.toString()] = true; postMessageToBrackets(MessageIds.REGISTER_BRACKETS_FUNCTIONS, initObj.requester.toString()); }