48 lines
2.0 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const isSubContext = wx.getOpenDataContext === undefined;
const sysinfo = wx.getSystemInfoSync();
const platform = sysinfo.platform.toLowerCase();
const isAndroid = platform === "android";
const isDevtools = platform === "devtools";
const sdkVersion = sysinfo.SDKVersion.split('.').map(Number);
// >= 2.20.2
const hasWorker = sdkVersion[0] > 2 || (sdkVersion[0] === 2 && (sdkVersion[1] > 20 || (sdkVersion[1] === 20 && sdkVersion[2] >= 2)));
// >= 2.27.3
const useSubpackage = sdkVersion[0] > 2 || (sdkVersion[0] === 2 && (sdkVersion[1] > 27 || (sdkVersion[1] === 27 && sdkVersion[2] >= 3)));
// 是否启用 Worker 驱动资源管线
if (!("CC_WORKER_ASSET_PIPELINE" in globalThis)) {
globalThis.CC_WORKER_ASSET_PIPELINE = false;
// NOTE 截止 2024.10.22,微信未修复 iOS、Windows、Mac 上仅文件系统 API 可以正常使用的问题
globalThis.CC_WORKER_ASSET_PIPELINE = (isAndroid || isDevtools) && globalThis.CC_WORKER_ASSET_PIPELINE;
}
// 是否启用 Worker 驱动音频系统
if (!("CC_WORKER_AUDIO_SYSTEM" in globalThis)) {
globalThis.CC_WORKER_AUDIO_SYSTEM = false;
}
// 是否启用 Worker
if (!("CC_USE_WORKER" in globalThis)) {
globalThis.CC_USE_WORKER = (CC_WORKER_ASSET_PIPELINE) && hasWorker && !isSubContext;
}
// 是否启用 Worker 调试模式
if (!("CC_WORKER_DEBUG" in globalThis)) {
globalThis.CC_WORKER_DEBUG = false;
}
// 是否启用 Worker 调度模式,这也许能减少通信次数带来的性能消耗(必须一致)
globalThis.CC_WORKER_SCHEDULER = true;
// 是否启用 Worker 使用同步版本的文件系统 API
// NOTE: IOS 不支持 async 文件系统 APIAndroid 不支持部分 sync 文件系统 API其余系统暂不确定
if (!("CC_WORKER_FS_SYNC" in globalThis)) {
globalThis.CC_WORKER_FS_SYNC = !isAndroid && !isDevtools;
}
// 是否启用 Worker 子包
if (!("CC_WORKER_SUB_PACKAGE" in globalThis)) {
// NOTE 截止 2024.10.22,部分安卓机型声明使用子包 Worker 会报 java.string 错误
globalThis.CC_WORKER_SUB_PACKAGE = false; // useSubpackage
}