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

Commit 0824eb4

Browse files
committed
mandatoryInstallMode
1 parent 99da36f commit 0824eb4

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-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: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ The simplest way to do this is to perform the following in your app's root compo
296296
codePush.sync();
297297
```
298298
299-
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.
299+
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 enduser 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.
300300
301301
<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>
302302
@@ -497,7 +497,9 @@ While the `sync` method tries to make it easy to perform silent and active updat
497497
498498
* __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`.
499499
500-
* __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.
500+
* __installMode__ *(codePush.InstallMode)* - Specifies when you would like to install optional updates (i.e. they 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.
501+
502+
* __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.
501503
502504
* __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).
503505
@@ -631,7 +633,7 @@ The CodePush API includes the following enums which can be used to customize the
631633
##### InstallMode
632634
633635
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:
634-
* __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.
636+
* __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 would remove the latency between the update installation and the next time the end user restarts or resumes the app.
635637
636638
* __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.
637639

0 commit comments

Comments
 (0)