From 3deea980b32086a8a51bf89391220a699f39fdd8 Mon Sep 17 00:00:00 2001 From: niteskum Date: Mon, 11 Jun 2018 18:58:49 +0530 Subject: [PATCH 1/2] Auto Update Error Handlng Fix --- .../default/AutoUpdate/MessageIds.js | 2 +- src/extensions/default/AutoUpdate/main.js | 23 +++++++++++-------- .../AutoUpdate/node/AutoUpdateDomain.js | 4 +++- 3 files changed, 18 insertions(+), 11 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..4e547c0036d 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({ @@ -321,6 +322,7 @@ define(function (require, exports, module) { */ function setupAutoUpdate() { updateJsonHandler = new StateHandler(updateJsonPath); + updateDomain.on('data', receiveMessageFromNode); updateDomain.exec('initNode', { messageIds: MessageIds, @@ -328,8 +330,6 @@ define(function (require, exports, module) { requester: domainID }); - updateDomain.on('data', receiveMessageFromNode); - initState(); } @@ -594,11 +594,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) { + if(reset) { + updateJsonHandler.parse() + .done(function() { + setUpdateStateInJSON("autoUpdateInProgress", !reset) + .always(initState); + }) + .fail(initState); + } else { + initState(); + } } @@ -636,7 +642,6 @@ define(function (require, exports, module) { enableCheckForUpdateEntry(true); console.error(message); - setUpdateStateInJSON("autoUpdateInProgress", false); } /** @@ -1124,7 +1129,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()); } From 27dde5c6e92a65779867dfc6708d75eecc9007f6 Mon Sep 17 00:00:00 2001 From: niteskum Date: Thu, 21 Jun 2018 21:37:15 +0530 Subject: [PATCH 2/2] Addressed Review comments --- src/extensions/default/AutoUpdate/main.js | 36 ++++++++++------------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/src/extensions/default/AutoUpdate/main.js b/src/extensions/default/AutoUpdate/main.js index 4e547c0036d..da8eff67c4b 100644 --- a/src/extensions/default/AutoUpdate/main.js +++ b/src/extensions/default/AutoUpdate/main.js @@ -281,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; @@ -312,7 +307,9 @@ define(function (require, exports, module) { break; } console.log(logMsg); + result.reject(); }); + return result.promise(); } @@ -329,7 +326,6 @@ define(function (require, exports, module) { updateDir: updateDir, requester: domainID }); - } @@ -595,16 +591,16 @@ define(function (require, exports, module) { * Enables/disables the state of "Auto Update In Progress" in UpdateHandler.json */ function nodeDomainInitialized(reset) { - if(reset) { - updateJsonHandler.parse() - .done(function() { - setUpdateStateInJSON("autoUpdateInProgress", !reset) - .always(initState); - }) - .fail(initState); - } else { - initState(); - } + initState() + .done(function () { + var inProgress = updateJsonHandler.get(updateProgressKey); + if (inProgress && reset) { + setUpdateStateInJSON(updateProgressKey, !reset) + .always(checkUpdateStatus); + } else if (!inProgress) { + checkUpdateStatus(); + } + }); }