Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.

Commit cca4422

Browse files
niteskumnethip
authored andcommitted
Auto Update Error Handlng Fix (#14412)
* Auto Update Error Handlng Fix * Addressed Review comments
1 parent 53a5254 commit cca4422

File tree

3 files changed

+24
-21
lines changed

3 files changed

+24
-21
lines changed

src/extensions/default/AutoUpdate/MessageIds.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,6 @@ define(function (require, exports, module) {
3838
exports.NOTIFY_INITIALIZATION_COMPLETE = "brackets.notifyinitializationComplete";
3939
exports.NOTIFY_VALIDATION_STATUS = "brackets.notifyvalidationStatus";
4040
exports.NOTIFY_INSTALLATION_STATUS = "brackets.notifyInstallationStatus";
41-
exports.SET_UPDATE_IN_PROGRESS_STATE = "brackets.setAutoUpdateInProgress";
41+
exports.NODE_DOMAIN_INITIALIZED = "brackets.nodeDomainInitialized";
4242
exports.REGISTER_BRACKETS_FUNCTIONS = "brackets.registerBracketsFunctions";
4343
});

src/extensions/default/AutoUpdate/main.js

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ define(function (require, exports, module) {
223223

224224
if (downloadCompleted && updateInitiatedInPrevSession) {
225225
var isNewVersion = checkIfVersionUpdated();
226+
updateJsonHandler.reset();
226227
if (isNewVersion) {
227228
// We get here if the update was successful
228229
UpdateInfoBar.showUpdateBar({
@@ -280,19 +281,14 @@ define(function (require, exports, module) {
280281

281282
/**
282283
* Initializes the state of parsed content from updateHelper.json
284+
* returns Promise Object Which is resolved when parsing is success
285+
* and rejected if parsing is failed.
283286
*/
284287
function initState() {
288+
var result = $.Deferred();
285289
updateJsonHandler.parse()
286290
.done(function() {
287-
checkIfAnotherSessionInProgress()
288-
.done(function (inProgress) {
289-
if (!inProgress) {
290-
checkUpdateStatus();
291-
}
292-
})
293-
.fail(function () {
294-
checkUpdateStatus();
295-
});
291+
result.resolve();
296292
})
297293
.fail(function (code) {
298294
var logMsg;
@@ -311,7 +307,9 @@ define(function (require, exports, module) {
311307
break;
312308
}
313309
console.log(logMsg);
310+
result.reject();
314311
});
312+
return result.promise();
315313
}
316314

317315

@@ -321,15 +319,13 @@ define(function (require, exports, module) {
321319
*/
322320
function setupAutoUpdate() {
323321
updateJsonHandler = new StateHandler(updateJsonPath);
322+
updateDomain.on('data', receiveMessageFromNode);
324323

325324
updateDomain.exec('initNode', {
326325
messageIds: MessageIds,
327326
updateDir: updateDir,
328327
requester: domainID
329328
});
330-
331-
updateDomain.on('data', receiveMessageFromNode);
332-
initState();
333329
}
334330

335331

@@ -594,11 +590,17 @@ define(function (require, exports, module) {
594590
/**
595591
* Enables/disables the state of "Auto Update In Progress" in UpdateHandler.json
596592
*/
597-
function setAutoUpdateInProgressFlag(flag) {
598-
updateJsonHandler.parse()
599-
.done(function() {
600-
setUpdateStateInJSON("autoUpdateInProgress", flag);
601-
});
593+
function nodeDomainInitialized(reset) {
594+
initState()
595+
.done(function () {
596+
var inProgress = updateJsonHandler.get(updateProgressKey);
597+
if (inProgress && reset) {
598+
setUpdateStateInJSON(updateProgressKey, !reset)
599+
.always(checkUpdateStatus);
600+
} else if (!inProgress) {
601+
checkUpdateStatus();
602+
}
603+
});
602604
}
603605

604606

@@ -636,7 +638,6 @@ define(function (require, exports, module) {
636638
enableCheckForUpdateEntry(true);
637639
console.error(message);
638640

639-
setUpdateStateInJSON("autoUpdateInProgress", false);
640641
}
641642

642643
/**
@@ -1124,7 +1125,7 @@ define(function (require, exports, module) {
11241125

11251126
ProjectManager.on("beforeProjectClose beforeAppClose", _handleAppClose);
11261127
}
1127-
functionMap["brackets.setAutoUpdateInProgress"] = setAutoUpdateInProgressFlag;
1128+
functionMap["brackets.nodeDomainInitialized"] = nodeDomainInitialized;
11281129
functionMap["brackets.registerBracketsFunctions"] = registerBracketsFunctions;
11291130

11301131
});

src/extensions/default/AutoUpdate/node/AutoUpdateDomain.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,15 +419,17 @@
419419
* requester : ID of the current requester domain}
420420
*/
421421
function initNode(initObj) {
422+
var resetUpdateProgres = false;
422423
if (!isNodeDomainInitialized) {
423424
MessageIds = initObj.messageIds;
424425
updateDir = path.resolve(initObj.updateDir);
425426
logFilePath = path.resolve(updateDir, logFile);
426427
installStatusFilePath = path.resolve(updateDir, installStatusFile);
427428
registerNodeFunctions();
428429
isNodeDomainInitialized = true;
429-
postMessageToBrackets(MessageIds.SET_UPDATE_IN_PROGRESS_STATE, initObj.requester.toString(), false);
430+
resetUpdateProgres = true;
430431
}
432+
postMessageToBrackets(MessageIds.NODE_DOMAIN_INITIALIZED, initObj.requester.toString(), resetUpdateProgres);
431433
requesters[initObj.requester.toString()] = true;
432434
postMessageToBrackets(MessageIds.REGISTER_BRACKETS_FUNCTIONS, initObj.requester.toString());
433435
}

0 commit comments

Comments
 (0)