Ai
1 Star 0 Fork 1

碳猫科技/react-native-code-push

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
RestartManager.js 1.63 KB
一键复制 编辑 原始数据 按行查看 历史
Geoffrey Goh 提交于 2016-06-29 07:35 +08:00 . Update RestartManager.js
const log = require("./logging");
const NativeCodePush = require("react-native").NativeModules.CodePush;
const RestartManager = (() => {
let _allowed = true;
let _restartInProgress = false;
let _restartQueue = [];
function allow() {
log("Re-allowing restarts");
_allowed = true;
if (_restartQueue.length) {
log("Executing pending restart");
restartApp(_restartQueue.shift(1));
}
}
function clearPendingRestart() {
_restartQueue = [];
}
function disallow() {
log("Disallowing restarts");
_allowed = false;
}
async function restartApp(onlyIfUpdateIsPending = false) {
if (_restartInProgress) {
log("Restart request queued until the current restart is completed");
_restartQueue.push(onlyIfUpdateIsPending);
} else if (!_allowed) {
log("Restart request queued until restarts are re-allowed");
_restartQueue.push(onlyIfUpdateIsPending);
} else {
_restartInProgress = true;
if (await NativeCodePush.restartApp(onlyIfUpdateIsPending)) {
// The app has already restarted, so there is no need to
// process the remaining queued restarts.
log("Restarting app");
return;
}
_restartInProgress = false;
if (_restartQueue.length) {
restartApp(_restartQueue.shift(1));
}
}
}
return {
allow,
clearPendingRestart,
disallow,
restartApp
};
})();
module.exports = RestartManager;
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Objective-C
1
https://gitee.com/hackcat/react-native-code-push.git
git@gitee.com:hackcat/react-native-code-push.git
hackcat
react-native-code-push
react-native-code-push
master

搜索帮助