Files
plugin-library/Assets/12.WeixinMinigame/Runtime/wechat-default/workers/response/index.js
stary 0d6faa56f4
All checks were successful
Plugin Library CI / publish (00.BuildOriginality) (push) Successful in 13s
Plugin Library CI / publish (00.StaryEvo) (push) Successful in 17s
Plugin Library CI / publish (00.StaryEvoTools) (push) Successful in 35s
Plugin Library CI / publish (01.HybridCLR) (push) Successful in 15s
Plugin Library CI / publish (02.InformationSave) (push) Successful in 3s
Plugin Library CI / publish (03.YooAsset) (push) Successful in 33s
Plugin Library CI / publish (04.AudioCore) (push) Successful in 3s
Plugin Library CI / publish (05.TableTextConversion) (push) Successful in 5s
Plugin Library CI / publish (06.UIFarme) (push) Successful in 15s
Plugin Library CI / publish (07.RKTools) (push) Successful in 2s
Plugin Library CI / publish (08.UniTask) (push) Successful in 3s
Plugin Library CI / publish (09.CodeChecker) (push) Successful in 16s
Plugin Library CI / publish (10.StoryEditor) (push) Successful in 3s
Plugin Library CI / publish (10.XNode) (push) Successful in 3s
Plugin Library CI / publish (11.PointCloudTools) (push) Successful in 2s
Plugin Library CI / publish (12.WeixinMinigame) (push) Successful in 2m32s
微信小程序编译
2026-04-19 00:16:03 +08:00

71 lines
2.2 KiB
JavaScript
Raw 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 messageType = {
config: 0,
writeFile: 1, // 写文件
};
// @ts-ignore SDK实际有暴露这几个API但是协议里没有
const { createSharedArrayBuffer, getFileSystemManager } = worker;
const fs = getFileSystemManager ? getFileSystemManager() : null;
function compareVersion(_v1, _v2) {
return (_v1
.split('.')
.map(v => v.padStart(2, '0'))
.join('')
>= _v2
.split('.')
.map(v => v.padStart(2, '0'))
.join(''));
}
worker.onMessage((res) => {
const { type, payload } = res;
if (type === messageType.writeFile) {
const { filePath, data, isSharedBuffer } = payload;
let content = data;
if (isSharedBuffer) {
content = data.buffer;
}
if (!fs) {
console.error('getFileSystemManager不存在');
return;
}
fs.writeFile({
filePath,
data: content,
success: () => {
worker.postMessage({
type: messageType.writeFile,
payload: {
isok: true,
filePath,
},
});
},
fail: (err) => {
worker.postMessage({
type: messageType.writeFile,
payload: {
isok: false,
filePath,
err,
},
});
},
});
}
if (type === messageType.config) {
const { systemInfo } = payload;
const { platform, version } = systemInfo;
// 安卓才需要使用worker写文件
const isAndroid = platform.toLocaleLowerCase() === 'android';
// 8.0.18以下版本出现写文件报错
const isClientValid = compareVersion(version, '8.0.18');
worker.postMessage({
type: messageType.config,
payload: {
supportWorkerFs: isAndroid && !!fs && isClientValid,
supportSharedBuffer: isAndroid && !!createSharedArrayBuffer,
},
});
}
});