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

Commit 1a49e76

Browse files
committed
work on issues from comments
-remove restartAllowed -add logging to RestartManager -keep track of pending restarts
1 parent 3ffa986 commit 1a49e76

File tree

4 files changed

+22
-16
lines changed

4 files changed

+22
-16
lines changed

CodePush.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Alert } from "./AlertAdapter";
33
import requestFetchAdapter from "./request-fetch-adapter";
44
import { AppState, Platform } from "react-native";
55
import RestartManager from "./RestartManager";
6+
import log from './logging';
67

78
let NativeCodePush = require("react-native").NativeModules.CodePush;
89
const PackageMixins = require("./package-mixins")(NativeCodePush);
@@ -155,11 +156,6 @@ function getPromisifiedSdk(requestFetchAdapter, config) {
155156
return sdk;
156157
}
157158

158-
/* Logs messages to console with the [CodePush] prefix */
159-
function log(message) {
160-
console.log(`[CodePush] ${message}`)
161-
}
162-
163159
// This ensures that notifyApplicationReadyInternal is only called once
164160
// in the lifetime of this module instance.
165161
const notifyApplicationReady = (() => {
@@ -411,7 +407,6 @@ if (NativeCodePush) {
411407
sync,
412408
disallowRestart: RestartManager.disallow,
413409
allowRestart: RestartManager.allow,
414-
restartAllowed: RestartManager.allowed,
415410
InstallMode: {
416411
IMMEDIATE: NativeCodePush.codePushInstallModeImmediate, // Restart the app immediately
417412
ON_NEXT_RESTART: NativeCodePush.codePushInstallModeOnNextRestart, // Don't artificially restart the app. Allow the update to be "picked up" on the next app restart

Examples/CodePushDemoApp/crossplatformdemo.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,16 +85,16 @@ let CodePushDemoApp = React.createClass({
8585
},
8686

8787
getInitialState() {
88-
return { };
88+
return { restartAllowed: true };
8989
},
9090

9191
toggleAllowRestart() {
92-
if (CodePush.restartAllowed()) {
92+
if (this.state.restartAllowed) {
9393
CodePush.disallowRestart();
9494
} else {
9595
CodePush.allowRestart();
9696
}
97-
this.forceUpdate();
97+
this.setState({restartAllowed: !this.state.restartAllowed});
9898
},
9999

100100
render() {
@@ -128,7 +128,7 @@ let CodePushDemoApp = React.createClass({
128128
{progressView}
129129
<Image style={styles.image} resizeMode={Image.resizeMode.contain} source={require('./images/laptop_phone_howitworks.png')}/>
130130
<Button onPress={this.toggleAllowRestart}>
131-
Restart { CodePush.restartAllowed() ? "allowed" : "forbidden"}
131+
Restart { this.state.restartAllowed ? "allowed" : "forbidden"}
132132
</Button>
133133
</View>
134134
);

RestartManager.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,36 @@
1+
let log = require('./logging');
12
let NativeCodePush = require("react-native").NativeModules.CodePush;
23

34
const RestartManager = (() => {
45
let _allowed = true;
6+
let _restartPending = false;
57

68
function restartApp(onlyIfUpdateIsPending = false) {
79
if (_allowed) {
810
NativeCodePush.restartApp(onlyIfUpdateIsPending);
11+
} else {
12+
log("restart not allowed");
13+
_restartPending = true;
914
}
1015
}
1116

1217
function allow() {
18+
log("allow restart");
1319
_allowed = true;
14-
restartApp(true);
15-
}
16-
17-
function allowed() {
18-
return _allowed
20+
if (_restartPending) {
21+
log("executing pending restart");
22+
restartApp(true);
23+
}
1924
}
2025

2126
function disallow() {
27+
log("disallow restart");
2228
_allowed = false;
2329
}
2430

2531
return {
2632
allow,
2733
disallow,
28-
allowed,
2934
restartApp,
3035
};
3136
})();

logging.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/* Logs messages to console with the [CodePush] prefix */
2+
function log(message) {
3+
console.log(`[CodePush] ${message}`);
4+
}
5+
6+
module.exports = log;

0 commit comments

Comments
 (0)