Tuanjie provides TypeScript interface that communicate with the UI thread worker. That you can use to interact with your custom method in TypeScript plug-in code (.etslib).
If you want to call your custom method in Tuanjie UI thread worker , you can use this function : CallOnUIThread
import { CallOnUIThread } from "./workers/TuanjieMainWorker";
parameters:
modulePath:string
: import module path ;moduleName:string
: the module will be registered to UI thread ;funcName:string
: the function name which you want to call ;param:Array<ESObject>
: function params , default value is empty [ ] ;callback
: function callBack , default value is null ;timeout:number
: If you need a synchronous call (timeout = –1 ), or if you need an asynchronous call ,please fill in the timeout (ms) , default value is –1 ;// in TestClass.etslib
import { CallOnUIThread } from "./workers/TuanjieMainWorker";
export class ClassObjectTest {
Func(arg1: ESObject, arg1: ESObject, callback: (...args: Array<ESObject>) => ESObject) {
let param:Array<ESObject> = [arg1, arg1];
CallOnUIThread("modulePath","CustomModule","CustomFunc",param,callback);
}
}
export function RegisterTestClass() {
const register :Record<string, Object> = {};
register["ClassObjectTest"] = ClassObjectTest;
return register;
}
Array<ESObject>
//in CustomModule
static async CustomFunc(arg1: ESObject, arg1: ESObject):Promise<Array<ESObject>>
{
return new Promise((resolve) => {
//if you need a context , you can use [globalThis.Abilitycontext] or [globalThis.UIContext]
CustomCall(arg1, arg1, globalThis.Abilitycontext).then((result:Array<ESObject>) => {
resolve(result);
}).catch((error: BusinessError) => {
let errorMsg :string = JSON.stringify(error);
let result:Array<ESObject> = [errorMsg];
resolve(result);
});
});
}
//in CustomModule
static CustomFunc(arg1: ESObject, arg1: ESObject)
{
let result:Array<ESObject> = CustomCall(arg1, arg1);
return result;
}