work on issues from comments
-remove restartAllowed -add logging to RestartManager -keep track of pending restarts
This commit is contained in:
Родитель
3ffa986670
Коммит
1a49e760cb
|
@ -3,6 +3,7 @@ import { Alert } from "./AlertAdapter";
|
|||
import requestFetchAdapter from "./request-fetch-adapter";
|
||||
import { AppState, Platform } from "react-native";
|
||||
import RestartManager from "./RestartManager";
|
||||
import log from './logging';
|
||||
|
||||
let NativeCodePush = require("react-native").NativeModules.CodePush;
|
||||
const PackageMixins = require("./package-mixins")(NativeCodePush);
|
||||
|
@ -155,11 +156,6 @@ function getPromisifiedSdk(requestFetchAdapter, config) {
|
|||
return sdk;
|
||||
}
|
||||
|
||||
/* Logs messages to console with the [CodePush] prefix */
|
||||
function log(message) {
|
||||
console.log(`[CodePush] ${message}`)
|
||||
}
|
||||
|
||||
// This ensures that notifyApplicationReadyInternal is only called once
|
||||
// in the lifetime of this module instance.
|
||||
const notifyApplicationReady = (() => {
|
||||
|
@ -411,7 +407,6 @@ if (NativeCodePush) {
|
|||
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
|
||||
|
|
|
@ -85,16 +85,16 @@ let CodePushDemoApp = React.createClass({
|
|||
},
|
||||
|
||||
getInitialState() {
|
||||
return { };
|
||||
return { restartAllowed: true };
|
||||
},
|
||||
|
||||
toggleAllowRestart() {
|
||||
if (CodePush.restartAllowed()) {
|
||||
if (this.state.restartAllowed) {
|
||||
CodePush.disallowRestart();
|
||||
} else {
|
||||
CodePush.allowRestart();
|
||||
}
|
||||
this.forceUpdate();
|
||||
this.setState({restartAllowed: !this.state.restartAllowed});
|
||||
},
|
||||
|
||||
render() {
|
||||
|
@ -128,7 +128,7 @@ let CodePushDemoApp = React.createClass({
|
|||
{progressView}
|
||||
<Image style={styles.image} resizeMode={Image.resizeMode.contain} source={require('./images/laptop_phone_howitworks.png')}/>
|
||||
<Button onPress={this.toggleAllowRestart}>
|
||||
Restart { CodePush.restartAllowed() ? "allowed" : "forbidden"}
|
||||
Restart { this.state.restartAllowed ? "allowed" : "forbidden"}
|
||||
</Button>
|
||||
</View>
|
||||
);
|
||||
|
|
|
@ -1,31 +1,36 @@
|
|||
let log = require('./logging');
|
||||
let NativeCodePush = require("react-native").NativeModules.CodePush;
|
||||
|
||||
const RestartManager = (() => {
|
||||
let _allowed = true;
|
||||
let _restartPending = false;
|
||||
|
||||
function restartApp(onlyIfUpdateIsPending = false) {
|
||||
if (_allowed) {
|
||||
NativeCodePush.restartApp(onlyIfUpdateIsPending);
|
||||
} else {
|
||||
log("restart not allowed");
|
||||
_restartPending = true;
|
||||
}
|
||||
}
|
||||
|
||||
function allow() {
|
||||
log("allow restart");
|
||||
_allowed = true;
|
||||
restartApp(true);
|
||||
}
|
||||
|
||||
function allowed() {
|
||||
return _allowed
|
||||
if (_restartPending) {
|
||||
log("executing pending restart");
|
||||
restartApp(true);
|
||||
}
|
||||
}
|
||||
|
||||
function disallow() {
|
||||
log("disallow restart");
|
||||
_allowed = false;
|
||||
}
|
||||
|
||||
return {
|
||||
allow,
|
||||
disallow,
|
||||
allowed,
|
||||
restartApp,
|
||||
};
|
||||
})();
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
/* Logs messages to console with the [CodePush] prefix */
|
||||
function log(message) {
|
||||
console.log(`[CodePush] ${message}`);
|
||||
}
|
||||
|
||||
module.exports = log;
|
Загрузка…
Ссылка в новой задаче