From bd2d12e2f56785ca74bbd3d225d56d9ccffaf9e5 Mon Sep 17 00:00:00 2001 From: Nikolay Igotti Date: Mon, 27 Jan 2025 19:24:33 +0300 Subject: [PATCH] Fix TypeScript with new rework Signed-off-by: Nikolay Igotti --- arkoala/framework/src/NativePeerNode.ts | 4 +--- arkoala/framework/src/PeerEvents.ts | 3 +-- arkoala/framework/src/PeerNode.ts | 3 +-- arkoala/framework/src/index.ts | 2 -- .../src => interop/src/interop}/NativeString.ts | 16 ++++------------ interop/src/interop/index.ts | 1 + 6 files changed, 8 insertions(+), 21 deletions(-) rename {arkoala/framework/src => interop/src/interop}/NativeString.ts (57%) diff --git a/arkoala/framework/src/NativePeerNode.ts b/arkoala/framework/src/NativePeerNode.ts index 7eba22ab4..883d28349 100644 --- a/arkoala/framework/src/NativePeerNode.ts +++ b/arkoala/framework/src/NativePeerNode.ts @@ -13,10 +13,8 @@ * limitations under the License. */ import { int32 } from "@koalaui/common" -import { pointer, withString, KStringPtr, nullptr, withStringResult, KInt, wrapCallback, disposeCallback } from "@koalaui/interop" -import { Finalizable } from "./Finalizable" +import { pointer, KInt, wrapCallback, disposeCallback, Finalizable } from "@koalaui/interop" import { ArkUINativeModule } from "./generated/ArkUINativeModule" -import { NativeString } from "./NativeString" import { PeerNode } from "./PeerNode" export class NativePeerNode extends Finalizable { diff --git a/arkoala/framework/src/PeerEvents.ts b/arkoala/framework/src/PeerEvents.ts index e03db4bca..33ed863c5 100644 --- a/arkoala/framework/src/PeerEvents.ts +++ b/arkoala/framework/src/PeerEvents.ts @@ -13,8 +13,7 @@ * limitations under the License. */ import { int32 } from "@koalaui/common" -import { Access, KInt32ArrayPtr, bitsToPtr, ptrToBits, withInt32Array } from "@koalaui/interop" -import { NativeString } from "./NativeString" +import { bitsToPtr, ptrToBits, NativeString } from "@koalaui/interop" // Must match ArkUIAPIEventKind in api.h. export enum PeerEventKind { diff --git a/arkoala/framework/src/PeerNode.ts b/arkoala/framework/src/PeerNode.ts index fd45f58c5..38837be4a 100644 --- a/arkoala/framework/src/PeerNode.ts +++ b/arkoala/framework/src/PeerNode.ts @@ -15,7 +15,7 @@ import { float32, int32 } from "@koalaui/common" import { Access, ptrToBits, withFloat32Array, KFloat32ArrayPtr, Wrapper, pointer, bitsToPtr, KPointer, KInt, KFloat, wrapCallback, - nullptr} from "@koalaui/interop" + nullptr, Finalizable } from "@koalaui/interop" import { ArkUINativeModule } from "./generated/ArkUINativeModule" import { DataNode, IncrementalNode, contextNode } from "@koalaui/runtime" import { @@ -33,7 +33,6 @@ import { } from "./PeerEvents" import { NativePeerNode } from "./NativePeerNode" import { WebLoadInterceptDataType } from "./WebResourceRequest" -import { Finalizable } from "./Finalizable" import { Alignment } from "./PeerLayout" export function IntToFloatArray(array: Int32Array, offset: number = 0, length?: number): Float32Array { diff --git a/arkoala/framework/src/index.ts b/arkoala/framework/src/index.ts index 546510f30..af410312e 100644 --- a/arkoala/framework/src/index.ts +++ b/arkoala/framework/src/index.ts @@ -15,7 +15,6 @@ export * from "./generated/ArkUINativeModule" export * from "./generated/TestNativeModule" -export * from "./NativeString" export * from "./PeerNode" export * from "./PeerEvents" export * from "./NativePeerNode" @@ -30,5 +29,4 @@ export * from "./PeerLayout" export * from "./utils" export * from "./LegacyWrapper" export * from "./ArkUINodeType" -export * from "./Finalizable" export { wrapCallback } from "@koalaui/interop" diff --git a/arkoala/framework/src/NativeString.ts b/interop/src/interop/NativeString.ts similarity index 57% rename from arkoala/framework/src/NativeString.ts rename to interop/src/interop/NativeString.ts index 274439f85..3e7affc56 100644 --- a/arkoala/framework/src/NativeString.ts +++ b/interop/src/interop/NativeString.ts @@ -13,26 +13,18 @@ * limitations under the License. */ -import { Access, decodeToString, pointer, withByteArray, withString, KStringPtr, KUint8ArrayPtr, InteropNativeModule } from "@koalaui/interop" import { Finalizable } from "./Finalizable" +import { InteropNativeModule } from "./InteropNativeModule" +import { pointer } from "./InteropTypes" export class NativeString extends Finalizable { constructor(ptr: pointer) { super(ptr, InteropNativeModule._GetStringFinalizer()) } static Make(value: string): NativeString { - let nativePtr = withString(value, (valuePtr: KStringPtr) => { - return InteropNativeModule._StringMake(valuePtr) - }) - return new NativeString(nativePtr) + return new NativeString(InteropNativeModule._StringMake(value)) } toString(): string { - // TODO: optimize me! - let size = InteropNativeModule._StringLength(this.ptr) - let array = new Uint8Array(size) - withByteArray(array, Access.WRITE, (arrayPtr: KUint8ArrayPtr) => { - InteropNativeModule._StringData(this.ptr, arrayPtr, size) - }) - return decodeToString(array) + return InteropNativeModule._StdStringToString(this.ptr) } } diff --git a/interop/src/interop/index.ts b/interop/src/interop/index.ts index eea216b14..5dcfa15a2 100644 --- a/interop/src/interop/index.ts +++ b/interop/src/interop/index.ts @@ -63,6 +63,7 @@ export * from "./Platform" export * from "./InteropTypes" export * from "./InteropOps" +export * from "./NativeString" export * from "./buffer" export * from "../arkts/ResourceManager" export * from "./NativeBuffer" -- Gitee