2024-10-21 20:23:37 +08:00
|
|
|
|
const isSubContext = wx.getOpenDataContext === undefined;
|
|
|
|
|
const sysinfo = wx.getSystemInfoSync();
|
|
|
|
|
const platform = sysinfo.platform.toLowerCase();
|
2024-10-22 17:17:13 +08:00
|
|
|
|
const isAndroid = platform === "android";
|
2024-10-24 17:27:28 +08:00
|
|
|
|
const isDevtools = platform === "devtools";
|
2024-10-21 20:23:37 +08:00
|
|
|
|
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)));
|
2024-10-24 17:27:28 +08:00
|
|
|
|
// >= 2.27.3
|
2024-11-25 19:47:57 +08:00
|
|
|
|
const hasSubpackage = sdkVersion[0] > 2 || (sdkVersion[0] === 2 && (sdkVersion[1] > 27 || (sdkVersion[1] === 27 && sdkVersion[2] >= 3)));
|
2024-10-21 20:23:37 +08:00
|
|
|
|
|
2024-10-24 17:27:28 +08:00
|
|
|
|
// 是否启用 Worker 驱动资源管线
|
2024-10-24 19:48:53 +08:00
|
|
|
|
if (!("CC_WORKER_ASSET_PIPELINE" in globalThis)) {
|
|
|
|
|
globalThis.CC_WORKER_ASSET_PIPELINE = false;
|
2024-11-25 19:47:57 +08:00
|
|
|
|
// NOTE 截止 2024.10.22,微信未修复 iOS、Windows、Mac 上不可用的问题
|
2024-10-24 19:48:53 +08:00
|
|
|
|
globalThis.CC_WORKER_ASSET_PIPELINE = (isAndroid || isDevtools) && globalThis.CC_WORKER_ASSET_PIPELINE;
|
|
|
|
|
}
|
2024-10-21 20:23:37 +08:00
|
|
|
|
|
2024-10-24 17:27:28 +08:00
|
|
|
|
// 是否启用 Worker 驱动音频系统
|
2024-10-24 19:48:53 +08:00
|
|
|
|
if (!("CC_WORKER_AUDIO_SYSTEM" in globalThis)) {
|
|
|
|
|
globalThis.CC_WORKER_AUDIO_SYSTEM = false;
|
2024-11-25 19:47:57 +08:00
|
|
|
|
// NOTE 截止 2024.10.22,微信未修复 iOS、Windows、Mac 上不可用的问题
|
2024-10-29 15:22:05 +08:00
|
|
|
|
globalThis.CC_WORKER_AUDIO_SYSTEM = (isAndroid || isDevtools) && globalThis.CC_WORKER_AUDIO_SYSTEM;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Worker 音频系统同步音频属性的间隔时间(单位:毫秒)
|
|
|
|
|
if (!("CC_WORKER_AUDIO_SYSTEM_SYNC_INTERVAL" in globalThis)) {
|
|
|
|
|
globalThis.CC_WORKER_AUDIO_SYSTEM_SYNC_INTERVAL = 500;
|
2024-10-24 19:48:53 +08:00
|
|
|
|
}
|
2024-10-22 17:17:13 +08:00
|
|
|
|
|
2024-11-14 20:03:04 +08:00
|
|
|
|
// 是否启用 Worker 驱动 HTTP 请求
|
|
|
|
|
if (!("CC_WORKER_HTTP_REQUEST" in globalThis)) {
|
|
|
|
|
globalThis.CC_WORKER_HTTP_REQUEST = false;
|
2024-11-25 19:47:57 +08:00
|
|
|
|
// NOTE 截止 2024.10.22,微信未修复 iOS、Windows、Mac 上不可用的问题
|
2024-11-14 20:03:04 +08:00
|
|
|
|
globalThis.CC_WORKER_HTTP_REQUEST = (isAndroid || isDevtools) && globalThis.CC_WORKER_HTTP_REQUEST;
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-22 16:54:43 +08:00
|
|
|
|
// 是否启用 Worker 驱动 WebSocket
|
|
|
|
|
if (!("CC_WORKER_WEBSOCKET" in globalThis)) {
|
|
|
|
|
globalThis.CC_WORKER_WEBSOCKET = false;
|
2024-11-25 19:47:57 +08:00
|
|
|
|
// NOTE 截止 2024.11.25,微信未修复 iOS、Windows、Mac、开发者工具上不可用的问题
|
|
|
|
|
globalThis.CC_WORKER_WEBSOCKET = (isAndroid) && globalThis.CC_WORKER_WEBSOCKET;
|
2024-11-22 16:54:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-11-07 17:36:59 +08:00
|
|
|
|
// 是否启用自定义 Worker
|
|
|
|
|
if (!("CC_CUSTOM_WORKER" in globalThis)) {
|
|
|
|
|
globalThis.CC_CUSTOM_WORKER = false;
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-21 20:23:37 +08:00
|
|
|
|
// 是否启用 Worker
|
2024-10-24 19:48:53 +08:00
|
|
|
|
if (!("CC_USE_WORKER" in globalThis)) {
|
2024-11-22 16:54:43 +08:00
|
|
|
|
globalThis.CC_USE_WORKER = (CC_WORKER_ASSET_PIPELINE || CC_WORKER_AUDIO_SYSTEM || CC_CUSTOM_WORKER || CC_WORKER_HTTP_REQUEST || CC_WORKER_WEBSOCKET) && hasWorker && !isSubContext;
|
2024-10-24 19:48:53 +08:00
|
|
|
|
}
|
2024-10-21 20:23:37 +08:00
|
|
|
|
|
|
|
|
|
// 是否启用 Worker 调试模式
|
2024-10-24 19:48:53 +08:00
|
|
|
|
if (!("CC_WORKER_DEBUG" in globalThis)) {
|
|
|
|
|
globalThis.CC_WORKER_DEBUG = false;
|
|
|
|
|
}
|
2024-10-21 20:23:37 +08:00
|
|
|
|
|
2024-11-07 17:36:59 +08:00
|
|
|
|
// 是否启用 Worker 调度模式,这也许能减少通信次数带来的性能消耗
|
2024-10-21 20:23:37 +08:00
|
|
|
|
globalThis.CC_WORKER_SCHEDULER = true;
|
|
|
|
|
|
|
|
|
|
// 是否启用 Worker 使用同步版本的文件系统 API
|
2024-10-22 17:17:13 +08:00
|
|
|
|
// NOTE: IOS 不支持 async 文件系统 API,Android 不支持部分 sync 文件系统 API,其余系统暂不确定
|
2024-10-24 19:48:53 +08:00
|
|
|
|
if (!("CC_WORKER_FS_SYNC" in globalThis)) {
|
|
|
|
|
globalThis.CC_WORKER_FS_SYNC = !isAndroid && !isDevtools;
|
|
|
|
|
}
|
2024-10-24 17:27:28 +08:00
|
|
|
|
|
|
|
|
|
// 是否启用 Worker 子包
|
2024-10-24 19:48:53 +08:00
|
|
|
|
if (!("CC_WORKER_SUB_PACKAGE" in globalThis)) {
|
2024-11-25 19:47:57 +08:00
|
|
|
|
globalThis.CC_WORKER_SUB_PACKAGE = false;
|
|
|
|
|
globalThis.CC_WORKER_SUB_PACKAGE = hasSubpackage && globalThis.CC_WORKER_SUB_PACKAGE;
|
2024-10-24 19:48:53 +08:00
|
|
|
|
}
|