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

Commit f9558e9

Browse files
committed
Merge pull request #221 from Microsoft/mandatory
mandatoryInstallMode
2 parents 86402cf + 82177e1 commit f9558e9

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

CodePush.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -227,21 +227,21 @@ const sync = (() => {
227227

228228
/*
229229
* The syncInternal method provides a simple, one-line experience for
230-
* incorporating the check, download and application of an update.
230+
* incorporating the check, download and installation of an update.
231231
*
232232
* It simply composes the existing API methods together and adds additional
233233
* support for respecting mandatory updates, ignoring previously failed
234234
* releases, and displaying a standard confirmation UI to the end-user
235235
* when an update is available.
236236
*/
237-
async function syncInternal(options = {}, syncStatusChangeCallback, downloadProgressCallback) {
237+
async function syncInternal(options = {}, syncStatusChangeCallback, downloadProgressCallback) {
238+
let resolvedInstallMode;
238239
const syncOptions = {
239-
240240
deploymentKey: null,
241241
ignoreFailedUpdates: true,
242242
installMode: CodePush.InstallMode.ON_NEXT_RESTART,
243+
mandatoryInstallMode: CodePush.InstallMode.IMMEDIATE,
243244
updateDialog: null,
244-
245245
...options
246246
};
247247

@@ -272,7 +272,7 @@ async function syncInternal(options = {}, syncStatusChangeCallback, downloadProg
272272
* If the install mode is IMMEDIATE, this will not get returned as the
273273
* app will be restarted to a new Javascript context.
274274
*/
275-
if (syncOptions.installMode == CodePush.InstallMode.ON_NEXT_RESTART) {
275+
if (resolvedInstallMode == CodePush.InstallMode.ON_NEXT_RESTART) {
276276
log("Update is installed and will be run on the next app restart.");
277277
} else {
278278
log("Update is installed and will be run when the app next resumes.");
@@ -300,8 +300,11 @@ async function syncInternal(options = {}, syncStatusChangeCallback, downloadProg
300300
syncStatusChangeCallback(CodePush.SyncStatus.DOWNLOADING_PACKAGE);
301301
const localPackage = await remotePackage.download(downloadProgressCallback);
302302

303+
// Determine the correct install mode based on whether the update is mandatory or not.
304+
resolvedInstallMode = localPackage.isMandatory ? syncOptions.mandatoryInstallMode : syncOptions.installMode;
305+
303306
syncStatusChangeCallback(CodePush.SyncStatus.INSTALLING_UPDATE);
304-
await localPackage.install(syncOptions.installMode, () => {
307+
await localPackage.install(resolvedInstallMode, () => {
305308
syncStatusChangeCallback(CodePush.SyncStatus.UPDATE_INSTALLED);
306309
});
307310

README.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ The simplest way to do this is to perform the following in your app's root compo
316316
codePush.sync();
317317
```
318318
319-
If an update is available, it will be silently downloaded, and installed the next time the app is restarted (either explicitly by the end user or by the OS), which ensures the least invasive experience for your end users. If you would like to display a confirmation dialog (an "active install"), or customize the update experience in any way, refer to the `sync` method's [API reference](#codepushsync) for information on how to tweak this default behavior.
319+
If an update is available, it will be silently downloaded, and installed the next time the app is restarted (either explicitly by the end user or by the OS), which ensures the least invasive experience for your end users. If an available update is mandatory, then it will be installed immediately, ensuring that the end user gets it as soon as possible. Additionally, if you would like to display a confirmation dialog (an "active install"), or customize the update experience in any way, refer to the `sync` method's [API reference](#codepushsync) for information on how to tweak this default behavior.
320320
321321
<a id="apple-note">*NOTE: While [Apple's developer agreement](https://developer.apple.com/programs/ios/information/iOS_Program_Information_4_3_15.pdf) fully allows performing over-the-air updates of JavaScript and assets (which is what enables CodePush!), it is against their policy for an app to display an update prompt. Because of this, we recommend that App Store-distributed apps don't enable the `updateDialog` option when calling `sync`, whereas Google Play and internally distributed apps (e.g. Enterprise, Fabric, HockeyApp) can choose to enable/customize it.*</a>
322322
@@ -517,7 +517,9 @@ While the `sync` method tries to make it easy to perform silent and active updat
517517
518518
* __deploymentKey__ *(String)* - Specifies the deployment key you want to query for an update against. By default, this value is derived from the `Info.plist` file (iOS) and `MainActivity.java` file (Android), but this option allows you to override it from the script-side if you need to dynamically use a different deployment for a specific call to `sync`.
519519
520-
* __installMode__ *(codePush.InstallMode)* - Indicates when you would like to "install" the update after downloading it, which includes reloading the JS bundle in order for any changes to take affect. Defaults to `codePush.InstallMode.ON_NEXT_RESTART`. Refer to the [`InstallMode`](#installmode) enum reference for a description of the available options and what they do.
520+
* __installMode__ *(codePush.InstallMode)* - Specifies when you would like to install optional updates (i.e. those that aren't marked as mandatory). Defaults to `codePush.InstallMode.ON_NEXT_RESTART`. Refer to the [`InstallMode`](#installmode) enum reference for a description of the available options and what they do.
521+
522+
* __mandatoryInstallMode__ *(codePush.InstallMode)* - Specifies when you would like to install updates which are marked as mandatory. Defaults to `codePush.InstallMode.IMMEDIATE`. Refer to the [`InstallMode`](#installmode) enum reference for a description of the available options and what they do.
521523
522524
* __updateDialog__ *(UpdateDialogOptions)* - An "options" object used to determine whether a confirmation dialog should be displayed to the end user when an update is available, and if so, what strings to use. Defaults to `null`, which has the effect of disabling the dialog completely. Setting this to any truthy value will enable the dialog with the default strings, and passing an object to this parameter allows enabling the dialog as well as overriding one or more of the default strings. Before enabling this option within an App Store-distributed app, please refer to [this note](#user-content-apple-note).
523525
@@ -552,6 +554,10 @@ codePush.sync({ deploymentKey: "KEY" });
552554
// instead of waiting until the app is restarted
553555
codePush.sync({ installMode: codePush.InstallMode.ON_NEXT_RESUME });
554556
557+
// Download the update silently, and install optional updates
558+
// on the next restart, but install mandatory updates on the next resume.
559+
codePush.sync({ mandatoryInstallMode: codePush.InstallMode.ON_NEXT_RESUME });
560+
555561
// Changing the title displayed in the
556562
// confirmation dialog of an "active" update
557563
codePush.sync({ updateDialog: { title: "An update is available!" } });
@@ -651,7 +657,8 @@ The CodePush API includes the following enums which can be used to customize the
651657
##### InstallMode
652658
653659
This enum specified when you would like an installed update to actually be applied, and can be passed to either the `sync` or `LocalPackage.install` methods. It includes the following values:
654-
* __codePush.InstallMode.IMMEDIATE__ *(0)* - Indicates that you want to install the update and restart the app immediately. This value is appropriate for debugging scenarios as well as when displaying an update prompt to the user, since they would expect to see the changes immediately after accepting the installation.
660+
661+
* __codePush.InstallMode.IMMEDIATE__ *(0)* - Indicates that you want to install the update and restart the app immediately. This value is appropriate for debugging scenarios as well as when displaying an update prompt to the user, since they would expect to see the changes immediately after accepting the installation. Additionally, this mode can be used to enforce mandatory updates, since it removes the potentially undesired latency between the update installation and the next time the end user restarts or resumes the app.
655662
656663
* __codePush.InstallMode.ON_NEXT_RESTART__ *(1)* - Indicates that you want to install the update, but not forcibly restart the app. When the app is "naturally" restarted (due the OS or end user killing it), the update will be seamlessly picked up. This value is appropriate when performing silent updates, since it would likely be disruptive to the end user if the app suddenly restarted out of nowhere, since they wouldn't have realized an update was even downloaded. This is the default mode used for both the `sync` and `LocalPackage.install` methods.
657664

0 commit comments

Comments
 (0)