This commit is contained in:
2026-09-24 16:25:22 +08:00
commit 7428184f01
1198 changed files with 314515 additions and 0 deletions
+83
View File
@@ -0,0 +1,83 @@
{
"id": "x-runnable-s",
"displayName": "x-runnable-s",
"version": "1.0.0",
"description": "x-runnable-s",
"keywords": [
"x-runnable-s"
],
"repository": "",
"engines": {
"HBuilderX": "^3.6.8"
},
"dcloudext": {
"type": "uts",
"sale": {
"regular": {
"price": "0.00"
},
"sourcecode": {
"price": "0.00"
}
},
"contact": {
"qq": ""
},
"declaration": {
"ads": "",
"data": "",
"permissions": ""
},
"npmurl": ""
},
"uni_modules": {
"dependencies": [],
"encrypt": [],
"platforms": {
"cloud": {
"tcb": "u",
"aliyun": "u",
"alipay": "u"
},
"client": {
"Vue": {
"vue2": "u",
"vue3": "u"
},
"App": {
"app-android": "u",
"app-ios": "u",
"app-harmony": "u"
},
"H5-mobile": {
"Safari": "u",
"Android Browser": "u",
"微信浏览器(Android)": "u",
"QQ浏览器(Android)": "u"
},
"H5-pc": {
"Chrome": "u",
"IE": "u",
"Edge": "u",
"Firefox": "u",
"Safari": "u"
},
"小程序": {
"微信": "u",
"阿里": "u",
"百度": "u",
"字节跳动": "u",
"QQ": "u",
"钉钉": "u",
"快手": "u",
"飞书": "u",
"京东": "u"
},
"快应用": {
"华为": "u",
"联盟": "u"
}
}
}
}
}
+8
View File
@@ -0,0 +1,8 @@
# x-runnable-s
### 开发文档
[UTS 语法](https://uniapp.dcloud.net.cn/tutorial/syntax-uts.html)
[UTS API插件](https://uniapp.dcloud.net.cn/plugin/uts-plugin.html)
[UTS uni-app兼容模式组件](https://uniapp.dcloud.net.cn/plugin/uts-component.html)
[UTS 标准模式组件](https://doc.dcloud.net.cn/uni-app-x/plugin/uts-vue-component.html)
[Hello UTS](https://gitcode.net/dcloud/hello-uts)
@@ -0,0 +1,3 @@
{
"minSdkVersion": "21"
}
@@ -0,0 +1,23 @@
export function runWorker(callback : () => any | null, resultCallback : (msg : any | null) => void) {
class IntentRunable extends Runnable {
dataResult:any|null;
constructor(data:any|null){
super()
this.dataResult = data;
}
override run() {
resultCallback(this.dataResult)
}
}
UTSAndroid.getDispatcher("io").async(function(_){
let data:any|null = callback();
UTSAndroid.getUniActivity()!.runOnUiThread(new IntentRunable(data))
},null)
}
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSPrivacyAccessedAPITypes</key>
<array/>
<key>NSPrivacyCollectedDataTypes</key>
<array/>
<key>NSPrivacyTracking</key>
<false/>
<key>NSPrivacyTrackingDomains</key>
<array/>
</dict>
</plist>
@@ -0,0 +1,3 @@
{
"deploymentTarget": "12"
}
@@ -0,0 +1,71 @@
import { DispatchQoS, DispatchConcurrentQueue, Operation, OperationQueue, Thread,DispatchTime } from "Foundation"
// Operation
class newThreadClassBytmui extends Operation {
task : () => any | null
result : any | null
init(@escaping callback : () => any | null) {
this.task = callback
super.init()
}
override main() {
this.result = this.task()
}
}
/** ios不支持直接传递函数进行多任务直接返回结果 */
export function runWorker(callback : () => any | null, resultCallback : (msg : any | null) => void) {
resultCallback(callback)
// DispatchQueue.global().asyncAfter(deadline = DispatchTime.now(),execute = ()=>{
// callback()
// })
// let callcalc = ():Promise<any|null> =>{
// return new Promise((res)=>{
// setTimeout(function() {
// res(callback())
// }, 1500);
// })
// };
// Thread.detachNewThread(()=>{
// callcalc().then((result:any|null)=>{
// console.log(result,'---')
// DispatchQueue.main.async(execute = () : void => {
// console.log(result,'***')
// resultCallback(result)
// })
// })
// })
// let thred = new Thread(block = () => {
// let data : any | null = callback();
// console.log(data)
// // DispatchQueue.main.async(execute = () : void => {
// // console.log(data)
// // })
// })
// thred.isMainThread = true;
// thred.start()
// OperationQueue
// let workerQueue = new OperationQueue()
// workerQueue.maxConcurrentOperationCount = 30
// let worker = new newThreadClassBytmui(callback = callback)
// worker.completionBlock = ()=>{
// DispatchQueue.main.async(execute = () : void => {
// console.log(worker.result)
// })
// }
// workerQueue.addOperation(worker)
// 在后台线程执行
// DispatchQueue(label = "xtm.omg.td2", qos = DispatchQoS.background, attributes = DispatchQueue.Attributes.concurrent)
// .async(execute = () : void => {
// let data : any | null = callback();
// resultCallback(data)
// // DispatchQueue.main.async(execute = () : void => {
// // })
// })
}
@@ -0,0 +1,44 @@
// 将函数转换为 Worker
function createWorker(workerFunction) {
// 将函数转换为字符串
const workerCode = `
const result = (${workerFunction.toString()})();
self.postMessage(result);
`;
// 创建 Blob
const blob = new Blob([workerCode], { type: 'application/javascript' });
// 创建 URL
const workerUrl = URL.createObjectURL(blob);
// 创建 Worker
const worker = new Worker(workerUrl);
// 清理 URL
worker.addEventListener('message', () => {
URL.revokeObjectURL(workerUrl);
});
return worker;
}
export function runWorker(callback : () => any | null, resultCallback : (msg : any | null) => void) {
// 创建 Worker
const worker = createWorker(callback);
// 接收结果
worker.onmessage = (event) => {
resultCallback(event.data)
// 删除旧的worder
worker.postMessage('remove')
};
// 错误处理
worker.onerror = (error) => {
console.error('Worker error:', error);
};
}