Skip to content

Commit

Permalink
AutoUpdate : Changing callbacks to promises (adobe#14285)
Browse files Browse the repository at this point in the history
* AutoUpdate : Changing callbacks to promises

* Addressing review comments
  • Loading branch information
mbhavi authored and shubhsnov committed May 15, 2018
1 parent ca5d2ae commit 27c7053
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions src/extensions/default/AutoUpdate/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,8 @@ define(function (require, exports, module) {
};

if (updateJsonHandler.get('latestBuildNumber') !== _updateParams.latestBuildNumber) {
setUpdateStateInJSON('latestBuildNumber', _updateParams.latestBuildNumber, initNodeFn);
setUpdateStateInJSON('latestBuildNumber', _updateParams.latestBuildNumber)
.done(initNodeFn);
} else {
initNodeFn();
}
Expand Down Expand Up @@ -555,21 +556,23 @@ define(function (require, exports, module) {

/**
* Sets the update state in updateHelper.json in Appdata
* @param {string} key - key to be set
* @param {string} value - value to be set
* @param {function} fn - the function
* to be called in case of
* successful setting of update state
*/
function setUpdateStateInJSON(key, value, fn) {
var func = fn || function () {};
* @param {string} key - key to be set
* @param {string} value - value to be set
* @returns {$.Deferred} - a jquery promise, that is resolved with
* success or failure of state update in json file
*/
function setUpdateStateInJSON(key, value) {
var result = $.Deferred();

updateJsonHandler.set(key, value)
.done(function () {
func();
result.resolve();
})
.fail(function () {
resetStateInFailure("AutoUpdate : Could not modify updatehelper.json");
result.reject();
});
return result.promise();
}

/**
Expand Down Expand Up @@ -606,7 +609,8 @@ define(function (require, exports, module) {

--downloadAttemptsRemaining;
};
setUpdateStateInJSON('downloadCompleted', false, downloadFn);
setUpdateStateInJSON('downloadCompleted', false)
.done(downloadFn);
}

/**
Expand Down Expand Up @@ -785,7 +789,8 @@ define(function (require, exports, module) {
resetStateInFailure("AutoUpdate : setUpdateParams could not be found in shell");
}
};
setUpdateStateInJSON('updateInitiatedInPrevSession', true, updateFn);
setUpdateStateInJSON('updateInitiatedInPrevSession', true)
.done(updateFn);
}

/**
Expand Down Expand Up @@ -858,7 +863,8 @@ define(function (require, exports, module) {
);
};

setUpdateStateInJSON('downloadCompleted', true, statusValidFn);
setUpdateStateInJSON('downloadCompleted', true)
.done(statusValidFn);
} else {

// Installer validation failed
Expand All @@ -873,7 +879,8 @@ define(function (require, exports, module) {
getLatestInstaller();
};

setUpdateStateInJSON('downloadCompleted', false, statusInvalidFn);
setUpdateStateInJSON('downloadCompleted', false)
.done(statusInvalidFn);
} else {

// If this is a new download, prompt the message on update bar
Expand Down

0 comments on commit 27c7053

Please sign in to comment.