mirror of
https://github.com/zhigang1992/react-native-code-push.git
synced 2026-05-14 02:14:52 +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 requestFetchAdapter from "./request-fetch-adapter";
|
||||
import { AppState, Platform } from "react-native";
|
||||
import RestartManager from "./RestartManager";
|
||||
|
||||
let NativeCodePush = require("react-native").NativeModules.CodePush;
|
||||
const PackageMixins = require("./package-mixins")(NativeCodePush);
|
||||
@@ -412,10 +413,14 @@ if (NativeCodePush) {
|
||||
restartApp,
|
||||
setUpTestDependencies,
|
||||
sync,
|
||||
disallowRestart: RestartManager.disallow,
|
||||
allowRestart: RestartManager.allow,
|
||||
restartAllowed: RestartManager.allowed,
|
||||
InstallMode: {
|
||||
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_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: {
|
||||
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 { DeviceEventEmitter } from "react-native";
|
||||
import RestartManager from "./RestartManager";
|
||||
|
||||
// This function is used to augment remote and local
|
||||
// package objects with additional functionality/properties
|
||||
@@ -44,6 +45,9 @@ module.exports = (NativeCodePush) => {
|
||||
if (installMode == NativeCodePush.codePushInstallModeImmediate) {
|
||||
NativeCodePush.restartApp(false);
|
||||
} else {
|
||||
if (installMode == NativeCodePush.codePushInstallModeOnNextRestartOpportunity) {
|
||||
RestartManager.requestRestart();
|
||||
}
|
||||
localPackage.isPending = true; // Mark the package as pending since it hasn't been applied yet
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user