Skip to content
This repository has been archived by the owner on Oct 7, 2024. It is now read-only.

Commit

Permalink
work on issues from comments
Browse files Browse the repository at this point in the history
-remove restartAllowed
-add logging to RestartManager
-keep track of pending restarts
  • Loading branch information
dbasedow committed May 23, 2016
1 parent 3ffa986 commit 1a49e76
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 16 deletions.
7 changes: 1 addition & 6 deletions CodePush.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 = (() => {
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions Examples/CodePushDemoApp/crossplatformdemo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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>
);
Expand Down
17 changes: 11 additions & 6 deletions RestartManager.js
Original file line number Diff line number Diff line change
@@ -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,
};
})();
Expand Down
6 changes: 6 additions & 0 deletions logging.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* Logs messages to console with the [CodePush] prefix */
function log(message) {
console.log(`[CodePush] ${message}`);
}

module.exports = log;

0 comments on commit 1a49e76

Please sign in to comment.