mirror of
https://github.com/zhigang1992/react-native-code-push.git
synced 2026-06-10 23:59:42 +08:00
46 lines
1011 B
JavaScript
46 lines
1011 B
JavaScript
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);
|
|
log('restaes');
|
|
} else {
|
|
log("restart not allowed");
|
|
_restartPending = true;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
function allow() {
|
|
log("allow restart");
|
|
_allowed = true;
|
|
if (_restartPending) {
|
|
log("executing pending restart");
|
|
restartApp(true);
|
|
}
|
|
}
|
|
|
|
function disallow() {
|
|
log("disallow restart");
|
|
_allowed = false;
|
|
}
|
|
|
|
function clearPendingRestart() {
|
|
_restartPending = false;
|
|
}
|
|
|
|
return {
|
|
allow,
|
|
disallow,
|
|
restartApp,
|
|
clearPendingRestart
|
|
};
|
|
})();
|
|
|
|
module.exports = RestartManager;
|