增加 启动后延迟更新开关.
使用此开关后,游戏包将在启动进入游戏后才请求更新信息, 直到重启后再打开游戏才应用更新. 优化热更流程,可以在构建完成后,再领奖注入热更,上传更新.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
window.beforeBoot = function () {
|
||||
|
||||
// console.log("游戏正在启动中.")
|
||||
if (window.remoteUrl) {
|
||||
const settings = window._CCSettings;
|
||||
@@ -11,16 +12,51 @@ window.beforeBoot = function () {
|
||||
window.boot();
|
||||
return;
|
||||
}
|
||||
// 游戏启动后再请求更新,避免影响启动速度.
|
||||
url += `?_t=${Math.random()}`;
|
||||
cc.log("请求更新地址:", url);
|
||||
|
||||
if (window.updateBefore) {
|
||||
_get(url).then(resp => {
|
||||
if (!resp) {
|
||||
window.boot();
|
||||
return;
|
||||
}
|
||||
window.localStorage.setItem('cur_ver_info', resp);
|
||||
window.onBooting();
|
||||
});
|
||||
} else {
|
||||
window.onBooting();
|
||||
_get(url).then(resp => {
|
||||
if (!resp) {
|
||||
return;
|
||||
}
|
||||
window.localStorage.setItem('cur_ver_info', resp);
|
||||
});
|
||||
}
|
||||
};
|
||||
window.onBooting = function () {
|
||||
// 请求缓存信息,判断是否需要更新.
|
||||
let assetStr = window.localStorage.getItem('cur_ver_info');
|
||||
if (!assetStr) {
|
||||
window.boot();
|
||||
} else {
|
||||
// console.log("当前版本信息:", assetStr);
|
||||
console.log("当前版本信息:", assetStr);
|
||||
let asset = JSON.parse(assetStr);
|
||||
window.mergeVersion(asset);
|
||||
window.boot();
|
||||
|
||||
// 判断当前是否有版本更新.
|
||||
const lastVer = window.localStorage.getItem('last_ver_code') || asset.versionCode;
|
||||
const curVer = asset.versionCode || 0;
|
||||
if (lastVer != curVer) {
|
||||
window.localStorage.setItem('new_ver_flag', "1");
|
||||
} else {
|
||||
window.localStorage.setItem('new_ver_flag', "0");
|
||||
}
|
||||
window.localStorage.setItem('last_ver_code', curVer);
|
||||
// 当前版本名称.
|
||||
window.localStorage.setItem('cur_ver_name', asset.versionName);
|
||||
}
|
||||
};
|
||||
window.mergeVersion = function (updateInfo) {
|
||||
@@ -41,3 +77,20 @@ window.mergeVersion = function (updateInfo) {
|
||||
}
|
||||
};
|
||||
|
||||
function _get(url) {
|
||||
return new Promise(resolve => {
|
||||
const ajax = new XMLHttpRequest();
|
||||
ajax.open("get", url, true);
|
||||
ajax.setRequestHeader("Content-Type", "application/json;charset=utf-8");
|
||||
ajax.onreadystatechange = function () {
|
||||
if (ajax.readyState == 4) {
|
||||
if (ajax.status == 200) {
|
||||
resolve(ajax.responseText);
|
||||
} else {
|
||||
resolve(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
ajax.send(null);
|
||||
});
|
||||
};
|
Reference in New Issue
Block a user