Skip to content

Commit

Permalink
Added intermediate SyncStatus callbacks. Updated samples and document…
Browse files Browse the repository at this point in the history
…ation.
  • Loading branch information
Daniel Lebu committed Dec 4, 2015
1 parent f606452 commit 4044745
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 22 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ Interface defining several options for customizing the [sync](#codepushsync) ope
- __installMode__: Used to specity the InstallMode used for the install operation. This is optional and defaults to InstallMode.ON_NEXT_RESTART.
- __ignoreFailedUpdates__: Optional boolean flag. If set, updates available on the server for which and update was attempted and rolled back will be ignored. Defaults to true. (boolean)
- __updatedialog__: Option used to enable, disable or customize the user interaction during sync. If set to false, user interaction will be disabled. If set to true, the user will be alerted or asked to confirm new updates, based on whether the update is mandatory. To customize the user dialog, this option can be set to a custom UpdateDialogOptions instance.

- __deploymentKey__: Option used to override the config.xml deployment key when checking for updates.

### UpdateDialogOptions
Interface defining the configuration options for the alert or confirmation dialog.
Expand Down
6 changes: 6 additions & 0 deletions bin/www/codePush.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,11 @@ var CodePush = (function () {
syncCallback && syncCallback(SyncStatus.UPDATE_INSTALLED);
};
var onDownloadSuccess = function (localPackage) {
syncCallback && syncCallback(SyncStatus.INSTALLING_UPDATE);
localPackage.install(onInstallSuccess, onError, syncOptions);
};
var downloadAndInstallUpdate = function (remotePackage) {
syncCallback && syncCallback(SyncStatus.DOWNLOADING_PACKAGE);
remotePackage.download(onDownloadSuccess, onError, downloadProgress);
};
var onUpdate = function (remotePackage) {
Expand All @@ -121,6 +123,9 @@ var CodePush = (function () {
}
else {
var dlgOpts = syncOptions.updateDialog;
if (dlgOpts) {
syncCallback && syncCallback(SyncStatus.AWAITING_USER_ACTION);
}
if (remotePackage.isMandatory && syncOptions.updateDialog) {
var message = dlgOpts.appendReleaseDescription ?
dlgOpts.mandatoryUpdateMessage + dlgOpts.descriptionPrefix + remotePackage.description
Expand Down Expand Up @@ -149,6 +154,7 @@ var CodePush = (function () {
}
}
};
syncCallback && syncCallback(SyncStatus.CHECKING_FOR_UPDATE);
window.codePush.checkForUpdate(onUpdate, onError, syncOptions.deploymentKey);
};
CodePush.prototype.getDefaultSyncOptions = function () {
Expand Down
2 changes: 1 addition & 1 deletion samples/advanced/www/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ var app = {
};

console.log("Installing package...");
localPackage.install(installCallback, app.getErrorHandler("Installation failed."));
localPackage.install(installCallback, app.getErrorHandler("Installation failed."), { installMode: InstallMode.IMMEDIATE });
},
// Returns an error handler that logs the error to the console and displays a notification containing the error message.
getErrorHandler: function (message) {
Expand Down
62 changes: 42 additions & 20 deletions samples/basic/www/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,28 +33,50 @@ var app = {
// The scope of 'this' is the event. In order to call the 'receivedEvent'
// function, we must explicitly call 'app.receivedEvent(...);'
onDeviceReady: function () {
/* Invoke sync with the default options, which enables user interaction.

/* Invoke sync with the custom options, which enables user interaction.
For customizing the sync behavior, see SyncOptions in the CodePush documentation. */
window.codePush.sync(function (syncStatus) {
switch (syncStatus) {
case SyncStatus.UPDATE_INSTALLED:
console.log("The update was applied successfully. This is the last callback before the application is reloaded with the updated content.");
/* Don't continue app initialization, the application will refresh after this return. */
return;
case SyncStatus.UP_TO_DATE:
app.displayMessage("The application is up to date.");
break;
case SyncStatus.UPDATE_IGNORED:
app.displayMessage("The user decided not to install the optional update.");
break;
case SyncStatus.ERROR:
app.displayMessage("An error occured while checking for updates");
break;
}
window.codePush.sync(
function (syncStatus) {
switch (syncStatus) {
// Result (final) statuses
case SyncStatus.UPDATE_INSTALLED:
app.displayMessage("The update was installed successfully. For InstallMode.ON_NEXT_RESTART, the changes will be visible after application restart. ");
break;
case SyncStatus.UP_TO_DATE:
app.displayMessage("The application is up to date.");
break;
case SyncStatus.UPDATE_IGNORED:
app.displayMessage("The user decided not to install the optional update.");
break;
case SyncStatus.ERROR:
app.displayMessage("An error occured while checking for updates");
break;

// Intermediate (non final) statuses
case SyncStatus.CHECKING_FOR_UPDATE:
console.log("Checking for update.");
break;
case SyncStatus.AWAITING_USER_ACTION:
console.log("Alerting user.");
break;
case SyncStatus.DOWNLOADING_PACKAGE:
console.log("Downloading package.");
break;
case SyncStatus.INSTALLING_UPDATE:
console.log("Installing update");
break;
}
},
{
installMode: InstallMode.ON_NEXT_RESTART, updateDialog: true
},
function (downloadProgress) {
console.log("Downloading " + downloadProgress.receivedBytes + " of " + downloadProgress.totalBytes + " bytes.");
});

// continue application initialization
app.receivedEvent('deviceready');
});
// continue application initialization
app.receivedEvent('deviceready');
},
// Update DOM on a Received Event
receivedEvent: function (id) {
Expand Down
6 changes: 6 additions & 0 deletions www/codePush.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,12 @@ class CodePush implements CodePushCordovaPlugin {
};

var onDownloadSuccess = (localPackage: ILocalPackage) => {
syncCallback && syncCallback(SyncStatus.INSTALLING_UPDATE);
localPackage.install(onInstallSuccess, onError, syncOptions);
};

var downloadAndInstallUpdate = (remotePackage: RemotePackage) => {
syncCallback && syncCallback(SyncStatus.DOWNLOADING_PACKAGE);
remotePackage.download(onDownloadSuccess, onError, downloadProgress);
};

Expand All @@ -191,6 +193,9 @@ class CodePush implements CodePushCordovaPlugin {
syncCallback && syncCallback(SyncStatus.UP_TO_DATE);
} else {
var dlgOpts: UpdateDialogOptions = <UpdateDialogOptions>syncOptions.updateDialog;
if (dlgOpts) {
syncCallback && syncCallback(SyncStatus.AWAITING_USER_ACTION);
}
if (remotePackage.isMandatory && syncOptions.updateDialog) {
/* Alert user */
var message = dlgOpts.appendReleaseDescription ?
Expand Down Expand Up @@ -224,6 +229,7 @@ class CodePush implements CodePushCordovaPlugin {
}
};

syncCallback && syncCallback(SyncStatus.CHECKING_FOR_UPDATE);
window.codePush.checkForUpdate(onUpdate, onError, syncOptions.deploymentKey);
}

Expand Down

0 comments on commit 4044745

Please sign in to comment.