Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

CodePush.sync() API method #22

Merged
merged 9 commits into from
Oct 29, 2015
Merged

CodePush.sync() API method #22

merged 9 commits into from
Oct 29, 2015

Conversation

lostintangent
Copy link
Member

This provides a simplified and opinionated one-line experience to CodePush-ifying an app. The CodePush.sync() method allows automating the act of checking for an update, downloading it and then subsequently applying it, all while also supporting ignoring previously failed updates, respecting mandatory updates and displaying a standard user confirmation dialog when updates are available.

The method takes an optional options object that can be used to customize the strings used when displaying the user dialog, as well as the rollback timeout.

It returns a Promise that will be resolved with a SyncStatus code, that indicates why the sync succeeded:

0 - No update was available, so the running app is up to do
1 - The app had an optional update, but the end-user chose to ignore it
2 - The app had an optional or mandatory update and the user accepted it

If a failure occurs at any point during the sync, the returned Promise will be rejected with the error reason.

I'll update the docs in a subsequent PR, but I just wanted to get this change out since the respective Cordova change is in review.

@geof90
Copy link
Contributor

geof90 commented Oct 29, 2015

LGTM!

return new Promise((resolve, reject) => {
checkForUpdate()
.then((remotePackage) => {
if (!remotePackage || (remotePackage.failedAppy && syncOptions.ignoreFailedUpdates)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

failedApply?

@dtivel
Copy link
Member

dtivel commented Oct 29, 2015

LGTM

remotePackage.download()
.then((localPackage) => {
resolve(CodePush.SyncStatus.UPDATE_DOWNLOADED);
localPackage.apply(syncOptions.rollbackTimeout);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey I don't think a failure in the apply promise is being handled here - would it be better to do:

   return localPackage.apply(syncOptions.rollbackTimeout);
})
.catch(reject)
.done();

@richardhuaaa
Copy link
Contributor

LGTM!

lostintangent added a commit that referenced this pull request Oct 29, 2015
@lostintangent lostintangent merged commit f0806be into master Oct 29, 2015
@lostintangent lostintangent deleted the codepush_sync branch October 29, 2015 20:47
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants