hot-update/packages/update-manager/templates/pre_main.js

44 lines
1.4 KiB
JavaScript
Raw Normal View History

2021-02-01 16:11:00 +00:00
window.beforeBoot = function () {
// console.log("游戏正在启动中.")
2021-02-01 16:11:00 +00:00
if (window.remoteUrl) {
const settings = window._CCSettings;
settings.server = window.remoteUrl;
//cc.log("远程资源地址:", settings.server);
2021-02-01 16:11:00 +00:00
}
let url = window.updateUrl || false;
if (!url) {
cc.log("未配置版本更新地址,跳过更新.")
window.boot();
return;
}
// 请求缓存信息,判断是否需要更新.
let assetStr = window.localStorage.getItem('cur_ver_info');
if (!assetStr) {
window.boot();
} else {
// console.log("当前版本信息:", assetStr);
let asset = JSON.parse(assetStr);
window.mergeVersion(asset);
window.boot();
}
2021-02-01 16:11:00 +00:00
};
window.mergeVersion = function (updateInfo) {
const settings = window._CCSettings;
const bundleVers = updateInfo.bundles;
settings.server = updateInfo.server;
2021-02-01 16:11:00 +00:00
if (bundleVers) {
for (let b in bundleVers) {
if (bundleVers[b] != settings.bundleVers[b]) {
// 配置中的bundleVer版本不一致,则添加到remote列表中去,以供远程加载.
if (settings.remoteBundles.indexOf(b) < 0) {
settings.remoteBundles.push(b);
console.log('bundle 有更新:', b, bundleVers[b]);
2021-02-01 16:11:00 +00:00
}
}
}
settings.bundleVers = bundleVers;
}
};
2021-02-01 16:11:00 +00:00