Version: 1.4
语言 : 中文
Call TypeScript plug-in code from C# scripts
Extend the default Tuanjie ability

Custom method Call UI thread worker from TypeScript plug-in code (.etslib)

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).

Tuanjie TypeScript function Introduction

If you want to call your custom method in Tuanjie UI thread worker , you can use this function : CallOnUIThread

Import Tuanjie TypeScript function

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 ;

Demo

Code of Custom TypeScript Plug-in(.etslib)

// 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;
}

If you need a callback to Tuanjie , Make sure the return type is Array<ESObject>

Code in Custom TypeScript Module
//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);
    });
  });
}
Code in Custom TypeScript Module
//in CustomModule
static CustomFunc(arg1: ESObject, arg1: ESObject)
{
  let result:Array<ESObject> = CustomCall(arg1, arg1);
  return result;
}
Call TypeScript plug-in code from C# scripts
Extend the default Tuanjie ability