mirror of
https://github.com/zhigang1992/react-native-code-push.git
synced 2026-05-28 23:51:07 +08:00
add code to delay automatic restarts
This commit is contained in:
@@ -2,6 +2,7 @@ import { AcquisitionManager as Sdk } from "code-push/script/acquisition-sdk";
|
|||||||
import { Alert } from "./AlertAdapter";
|
import { Alert } from "./AlertAdapter";
|
||||||
import requestFetchAdapter from "./request-fetch-adapter";
|
import requestFetchAdapter from "./request-fetch-adapter";
|
||||||
import { AppState, Platform } from "react-native";
|
import { AppState, Platform } from "react-native";
|
||||||
|
import RestartManager from "./RestartManager";
|
||||||
|
|
||||||
let NativeCodePush = require("react-native").NativeModules.CodePush;
|
let NativeCodePush = require("react-native").NativeModules.CodePush;
|
||||||
const PackageMixins = require("./package-mixins")(NativeCodePush);
|
const PackageMixins = require("./package-mixins")(NativeCodePush);
|
||||||
@@ -412,10 +413,14 @@ if (NativeCodePush) {
|
|||||||
restartApp,
|
restartApp,
|
||||||
setUpTestDependencies,
|
setUpTestDependencies,
|
||||||
sync,
|
sync,
|
||||||
|
disallowRestart: RestartManager.disallow,
|
||||||
|
allowRestart: RestartManager.allow,
|
||||||
|
restartAllowed: RestartManager.allowed,
|
||||||
InstallMode: {
|
InstallMode: {
|
||||||
IMMEDIATE: NativeCodePush.codePushInstallModeImmediate, // Restart the app immediately
|
IMMEDIATE: NativeCodePush.codePushInstallModeImmediate, // Restart the app immediately
|
||||||
ON_NEXT_RESTART: NativeCodePush.codePushInstallModeOnNextRestart, // Don't artificially restart the app. Allow the update to be "picked up" on the next app restart
|
ON_NEXT_RESTART: NativeCodePush.codePushInstallModeOnNextRestart, // Don't artificially restart the app. Allow the update to be "picked up" on the next app restart
|
||||||
ON_NEXT_RESUME: NativeCodePush.codePushInstallModeOnNextResume // Restart the app the next time it is resumed from the background
|
ON_NEXT_RESUME: NativeCodePush.codePushInstallModeOnNextResume, // Restart the app the next time it is resumed from the background
|
||||||
|
ON_NEXT_RESTART_OPPORTUNITY: NativeCodePush.codePushInstallModeOnNextRestartOpportunity
|
||||||
},
|
},
|
||||||
SyncStatus: {
|
SyncStatus: {
|
||||||
CHECKING_FOR_UPDATE: 0,
|
CHECKING_FOR_UPDATE: 0,
|
||||||
|
|||||||
39
RestartManager.js
Normal file
39
RestartManager.js
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
let NativeCodePush = require("react-native").NativeModules.CodePush;
|
||||||
|
|
||||||
|
const RestartManager = (() => {
|
||||||
|
let _allowed = true;
|
||||||
|
let restartPending = false;
|
||||||
|
|
||||||
|
function tryRestart() {
|
||||||
|
if (restartPending && _allowed == true) {
|
||||||
|
NativeCodePush.restartApp(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function requestRestart() {
|
||||||
|
restartPending = true;
|
||||||
|
tryRestart();
|
||||||
|
}
|
||||||
|
|
||||||
|
function allow() {
|
||||||
|
_allowed = true;
|
||||||
|
tryRestart();
|
||||||
|
}
|
||||||
|
|
||||||
|
function allowed() {
|
||||||
|
return _allowed
|
||||||
|
}
|
||||||
|
|
||||||
|
function disallow() {
|
||||||
|
_allowed = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
allow,
|
||||||
|
disallow,
|
||||||
|
allowed,
|
||||||
|
requestRestart
|
||||||
|
};
|
||||||
|
})();
|
||||||
|
|
||||||
|
module.exports = RestartManager;
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
import { AcquisitionManager as Sdk } from "code-push/script/acquisition-sdk";
|
import { AcquisitionManager as Sdk } from "code-push/script/acquisition-sdk";
|
||||||
import { DeviceEventEmitter } from "react-native";
|
import { DeviceEventEmitter } from "react-native";
|
||||||
|
import RestartManager from "./RestartManager";
|
||||||
|
|
||||||
// This function is used to augment remote and local
|
// This function is used to augment remote and local
|
||||||
// package objects with additional functionality/properties
|
// package objects with additional functionality/properties
|
||||||
@@ -44,6 +45,9 @@ module.exports = (NativeCodePush) => {
|
|||||||
if (installMode == NativeCodePush.codePushInstallModeImmediate) {
|
if (installMode == NativeCodePush.codePushInstallModeImmediate) {
|
||||||
NativeCodePush.restartApp(false);
|
NativeCodePush.restartApp(false);
|
||||||
} else {
|
} else {
|
||||||
|
if (installMode == NativeCodePush.codePushInstallModeOnNextRestartOpportunity) {
|
||||||
|
RestartManager.requestRestart();
|
||||||
|
}
|
||||||
localPackage.isPending = true; // Mark the package as pending since it hasn't been applied yet
|
localPackage.isPending = true; // Mark the package as pending since it hasn't been applied yet
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user