From 0916c2684fedac4b461800fa9f3fc82e7de72450 Mon Sep 17 00:00:00 2001 From: Kirill Kirichenko Date: Wed, 4 Dec 2024 10:49:09 +0300 Subject: [PATCH 1/9] Initial commit Signed-off-by: Kirill Kirichenko --- arkoala-arkts/arkui/src/generated/PeerNode.ts | 4 +-- .../har/arkoala-har-bundle/load_page.mjs | 2 +- arkoala-arkts/har/package.json | 13 ++------- .../har/scripts/build-arkoala-har.mjs | 29 ++++++++++++------- arkoala-arkts/package.json | 11 ++++--- arkoala-arkts/user/package.json | 9 +++--- arkoala-arkts/user/scripts/build-user-har.mjs | 20 +++++++++---- arkoala/framework/native/meson.build | 3 +- .../framework/native/src/generated/library.cc | 25 ++++++++++++++-- 9 files changed, 74 insertions(+), 42 deletions(-) diff --git a/arkoala-arkts/arkui/src/generated/PeerNode.ts b/arkoala-arkts/arkui/src/generated/PeerNode.ts index 6e4dbee13..fe1aacfdf 100644 --- a/arkoala-arkts/arkui/src/generated/PeerNode.ts +++ b/arkoala-arkts/arkui/src/generated/PeerNode.ts @@ -31,9 +31,9 @@ export class PeerNode extends IncrementalNode { if (node!.isKind(PeerNodeType)) { sibling = node as PeerNode break + } } - } - this.peer.insertChildAfter(peer.peer, sibling?.peer) + this.peer.insertChildAfter(peer.peer, sibling?.peer) } } this.onChildRemoved = (child: IncrementalNode) => { diff --git a/arkoala-arkts/har/arkoala-har-bundle/load_page.mjs b/arkoala-arkts/har/arkoala-har-bundle/load_page.mjs index e3721683f..13d44c855 100644 --- a/arkoala-arkts/har/arkoala-har-bundle/load_page.mjs +++ b/arkoala-arkts/har/arkoala-har-bundle/load_page.mjs @@ -1,4 +1,4 @@ -let loader = () => { throw new Error("Page laoder was not set") } +let loader = () => { throw new Error("Page loader was not set") } export function __setPageLoader(fn) { loader = fn; diff --git a/arkoala-arkts/har/package.json b/arkoala-arkts/har/package.json index 3683f493f..61716d278 100644 --- a/arkoala-arkts/har/package.json +++ b/arkoala-arkts/har/package.json @@ -18,16 +18,9 @@ }, "scripts": { "clean": "rimraf app/arkoala/build app/arkoala/libs app/arkoala/bundle.js arkoala-har-bundle/dist", - "compile:arkoala-arkts": "npm run --prefix ../arkui compile:arkts:unmemoized && npm run build:incremental:components --prefix ../../incremental/runtime && npm run link:arkts --prefix ../arkui", - "native:clean": "npm run --prefix ../../arkoala/framework clean", - "native:build": "npm run --prefix ../../arkoala/framework compile:native-panda-with-hzvm-ohos-arm64", - "native:build-arm32": "npm run --prefix ../../arkoala/framework compile:native-panda-with-hzvm-ohos-arm32", - "bundle": "node scripts/build-arkoala-har.mjs --arch arm", - "build": "npm run cli-tools:check && cd app && DEVECO_SDK_HOME=../../../arkoala/ohos-sdk/ohos-sdk ../command-line-tools/hvigor/bin/hvigorw --no-daemon --mode module -p product=default -p module=arkoala@default assembleHar", - "arkoala:har": "npm run --prefix ../../arkoala/ohos-sdk download && npm run bundle && npm run build", - "arkoala:har-arm32": "npm run --prefix ../../arkoala/ohos-sdk download && npm run bundle && npm run build", - "all": "npm run native:clean && npm run compile:arkoala && npm run native:build && npm run arkoala:har", - "all-arm32": "npm run native:clean && npm run compile:arkoala-arkts && npm run native:build-arm32 && npm run arkoala:har-arm32", + "pack": "npm run cli-tools:check && cd app && DEVECO_SDK_HOME=../../../arkoala/ohos-sdk/ohos-sdk ../command-line-tools/hvigor/bin/hvigorw --no-daemon --mode module -p product=default -p module=arkoala@default assembleHar", + "har-arm32": "npm run --prefix ../../arkoala/ohos-sdk download && node scripts/build-arkoala-har.mjs --arch arm32 && npm run pack", + "har-arm64": "npm run --prefix ../../arkoala/ohos-sdk download && node scripts/build-arkoala-har.mjs --arch arm64 && npm run pack", "cli-tools:chmod:bz": "node ../../arkoala/ohos-sdk/scripts/openlab-cli.mjs chmod -p ./command-line-tools/ohpm/bin -b 755 && node ../../arkoala/ohos-sdk/scripts/openlab-cli.mjs chmod -p ./command-line-tools/hvigor/bin -b 755", "cli-tools:chmod:yz": "node ../../../sdk/scripts/gitlab/gitlab-cli.mjs chmod -p ./command-line-tools/ohpm/bin -b 755 && node ../../../sdk/scripts/gitlab/gitlab-cli.mjs chmod -p ./command-line-tools/hvigor/bin -b 755", "cli-tools:download:bz": "node ../../arkoala/ohos-sdk/scripts/openlab-cli.mjs download -p command-line-tools -v 5.0.3502 -f command-line-tools.5.0.3502.zip -d command-line-tools && npm run cli-tools:chmod:bz", diff --git a/arkoala-arkts/har/scripts/build-arkoala-har.mjs b/arkoala-arkts/har/scripts/build-arkoala-har.mjs index a7279c2a2..733ec1e44 100644 --- a/arkoala-arkts/har/scripts/build-arkoala-har.mjs +++ b/arkoala-arkts/har/scripts/build-arkoala-har.mjs @@ -15,6 +15,10 @@ const CWD = process.cwd() const BUNDLE_PATH = path.join(CWD, "arkoala-har-bundle") const HAR_PATH = path.join(CWD, "app/arkoala") +function execCmdSync(cmd, options) { + return execSync(cmd, options).toString().trim().replace("\n", " ") +} + function rollupLaunch() { console.log(`> Run rollup`) execCmdSync("npx rollup -c") @@ -30,21 +34,26 @@ function copyFilesToHar(from, to) { } -function main() { +function main(targetLibDir) { process.chdir(BUNDLE_PATH) rollupLaunch() /* we don't yet know which files should be in har */ - copyFilesToHar(path.join(_dirname, `../../../arkoala/framework/build/libc++.so`), path.join(HAR_PATH, `libs/armeabi-v7a/libc++.so`)) - copyFilesToHar(path.join(_dirname, `../../../arkoala/framework/native/build-hzvm-ohos-arm32-vmloader/libArkoalaLoader.so`), path.join(HAR_PATH, `libs/armeabi-v7a/libArkoalaLoader.so`)) - copyFilesToHar(path.join(_dirname, `../../../arkoala/framework/native/build-hzvm-ohos-arm32-vmloader/libvmloader.so`), path.join(HAR_PATH, `libs/armeabi-v7a/libvmloader.so`)) - copyFilesToHar(path.join(_dirname, `../../../arkoala/framework/native/build-panda-ohos-arm32/libArkoalaNative_ark.so`), path.join(HAR_PATH, `libs/armeabi-v7a/libArkoalaNative_ark.so`)) - copyFilesToHar(path.join(_dirname, `../../build/arkoala.abc`), path.join(HAR_PATH, `libs/armeabi-v7a/arkoala.abc.so`)) + copyFilesToHar(path.join(_dirname, `../../../arkoala/framework/build/libc++.so`), path.join(HAR_PATH, `libs/${targetLibDir}/libc++.so`)) + copyFilesToHar(path.join(_dirname, `../../../arkoala/framework/build/libArkoalaLoader.so`), path.join(HAR_PATH, `libs/${targetLibDir}/libArkoalaLoader.so`)) + copyFilesToHar(path.join(_dirname, `../../../arkoala/framework/build/libvmloader.so`), path.join(HAR_PATH, `libs/${targetLibDir}/libvmloader.so`)) + copyFilesToHar(path.join(_dirname, `../../../arkoala/framework/build/libArkoalaNative_ark.so`), path.join(HAR_PATH, `libs/${targetLibDir}/libArkoalaNative_ark.so`)) + copyFilesToHar(path.join(_dirname, `../../build/arkoala.abc`), path.join(HAR_PATH, `libs/${targetLibDir}/arkoala.abc.so`)) } -main() - -function execCmdSync(cmd, options) { - return execSync(cmd, options).toString().trim().replace("\n", " ") +const arch = args["arch"] +if (arch == "arm32") { + main("armeabi-v7a", arch) +} else if (arch == "arm64") { + main("arm64-v8a", arch) + copyFilesToHar(path.join(_dirname, `../../../arkoala/framework/build/libace_compatible_mock.so`), path.join(HAR_PATH, `libs/arm64-v8a/libace_compatible_mock.so`)) +} else { + console.log("Unsupported architecture: ", arch) + exit(1) } diff --git a/arkoala-arkts/package.json b/arkoala-arkts/package.json index 6935e6ace..aa9c40cbc 100644 --- a/arkoala-arkts/package.json +++ b/arkoala-arkts/package.json @@ -35,8 +35,8 @@ "panda:sdk:install": "PANDA_SDK_VERSION=1.5.0-dev.9440 npm run panda:sdk:install --prefix ../incremental/tools/panda", "compile:native:node-host": "npm run compile:native-panda-with-node-host --prefix ../arkoala/framework", "compile:native:hzvm-ohos-arm32": "npm run compile:native-panda-with-hzvm-ohos-arm32 --prefix ../arkoala/framework", + "compile:native:hzvm-ohos-arm64": "npm run compile:native-panda-with-hzvm-ohos-arm64 --prefix ../arkoala/framework", "build:loader:node": "npm run build:loader:node --prefix loader", - "build:loader:hzvm-ohos-arm32": "npm run build:loader:ohos-arm32 --prefix loader", "build:incremental": "npm run build:incremental --prefix ../incremental/runtime", "build:incremental:inc": "npm run build:incremental:inc --prefix ../incremental/runtime", "clean:incremental": "npm run clean:incremental --prefix ../incremental/runtime", @@ -60,9 +60,12 @@ "trivial:all:node": "npm run compile:native:node-host && npm run build:arkoala && npm run build:user && npm run build:loader:node && npm run run:node", "trivial:node": "npm run build:user && npm run build:loader:node && npm run run:node", "trivial:all:node:ci": "npm run compile:native:node-host && npm run build:arkoala && npm run build:user && npm run build:loader:node && npm run run:node:ci", - "trivial:all:har-arm32": "npm run compile:native:hzvm-ohos-arm32 && npm run build:arkoala && npm run arkoala:har-arm32 --prefix har", - "clean": "rimraf build user/build", + "arkoala:har-arm32": "npm run compile:native:hzvm-ohos-arm32 && npm run build:arkoala && npm run har-arm32 --prefix har", + "arkoala:har-arm64": "npm run compile:native:hzvm-ohos-arm64 && npm run build:arkoala && npm run har-arm64 --prefix har", + "user:har-arm32": "npm run har-arm32 --prefix user", + "user:har-arm64": "npm run har-arm64 --prefix user", + "clean": "rimraf build", "clean:native": "npm run clean --prefix ../arkoala/framework", - "clean:all": "npm run clean && npm run clean:incremental && npm run clean:interop && npm run clean:arkui-common && npm run clean:arkui-no-common && npm run clean:native" + "clean:all": "npm run clean && npm run clean:incremental && npm run clean:interop && npm run clean:arkui-common && npm run clean:arkui-no-common && npm run clean:native && npm run clean --prefix har && npm run clean --prefix user" } } diff --git a/arkoala-arkts/user/package.json b/arkoala-arkts/user/package.json index 3884c8279..6ea9c64e8 100644 --- a/arkoala-arkts/user/package.json +++ b/arkoala-arkts/user/package.json @@ -3,7 +3,7 @@ "version": "1.4.1", "description": "", "scripts": { - "clean": "rimraf build generated unmemoized js_output abc lib ", + "clean": "rimraf build generated unmemoized js_output abc lib app/user/build", "compile:plugin": "cd ../../arkoala/ets-plugin && npm run compile", "compile:ets": "npm run compile:plugin && cd src/ets && ets-tsc -p ./etsconfig.json", "unmemoize": "npm run compile:ets && memo-tsc -p tsconfig-unmemoize.json", @@ -14,10 +14,9 @@ "compile:user": "npm run unmemoize:all && bash ../../incremental/tools/panda/arkts/arktsc --arktsconfig arktsconfig-run-unmemoized.json --ets-module", "build:user": "npm run compile:user && bash ../../incremental/tools/panda/arkts/arklink --output build/user.abc -- $(find build/abc -name '*.abc' ! -name 'index.abc')", - "bundle": "node scripts/build-user-har.mjs --arch arm", - "build": "npm run cli-tools:check && cd app && DEVECO_SDK_HOME=../../../arkoala/ohos-sdk/ohos-sdk ../command-line-tools/hvigor/bin/hvigorw --no-daemon --mode module -p product=default -p module=user@default assembleHar", - "user:har": "npm run build:user && npm run --prefix ../../arkoala/ohos-sdk download && npm run bundle && npm run build", - "user:har-arm32": "npm run user:har", + "pack": "npm run cli-tools:check && cd app && DEVECO_SDK_HOME=../../../arkoala/ohos-sdk/ohos-sdk ../command-line-tools/hvigor/bin/hvigorw --no-daemon --mode module -p product=default -p module=user@default assembleHar", + "har-arm32": "npm run build:user && npm run --prefix ../../arkoala/ohos-sdk download && node scripts/build-user-har.mjs --arch arm32 && npm run pack", + "har-arm64": "npm run build:user && npm run --prefix ../../arkoala/ohos-sdk download && node scripts/build-user-har.mjs --arch arm64 && npm run pack", "cli-tools:chmod:bz": "node ../../arkoala/ohos-sdk/scripts/openlab-cli.mjs chmod -p ./command-line-tools/ohpm/bin -b 755 && node ../../arkoala/ohos-sdk/scripts/openlab-cli.mjs chmod -p ./command-line-tools/hvigor/bin -b 755", "cli-tools:chmod:yz": "node ../../../sdk/scripts/gitlab/gitlab-cli.mjs chmod -p ./command-line-tools/ohpm/bin -b 755 && node ../../../sdk/scripts/gitlab/gitlab-cli.mjs chmod -p ./command-line-tools/hvigor/bin -b 755", diff --git a/arkoala-arkts/user/scripts/build-user-har.mjs b/arkoala-arkts/user/scripts/build-user-har.mjs index 54d293afb..82c4b71b4 100644 --- a/arkoala-arkts/user/scripts/build-user-har.mjs +++ b/arkoala-arkts/user/scripts/build-user-har.mjs @@ -15,6 +15,10 @@ const CWD = process.cwd() // const BUNDLE_PATH = path.join(CWD, "arkoala-har-bundle") const HAR_PATH = path.join(CWD, "app/user") +function execCmdSync(cmd, options) { + return execSync(cmd, options).toString().trim().replace("\n", " ") +} + function rollupLaunch() { console.log(`> Run rollup`) execCmdSync("npx rollup -c") @@ -30,17 +34,21 @@ function copyFilesToHar(from, to) { } -function main() { +function main(targetLibDir) { // process.chdir(BUNDLE_PATH) // rollupLaunch() /* we don't yet know which files should be in har */ - copyFilesToHar(path.join(_dirname, `../build/user.abc`), path.join(HAR_PATH, `libs/armeabi-v7a/user.abc.so`)) + copyFilesToHar(path.join(_dirname, `../build/user.abc`), path.join(HAR_PATH, `libs/${targetLibDir}/user.abc.so`)) } -main() - -function execCmdSync(cmd, options) { - return execSync(cmd, options).toString().trim().replace("\n", " ") +const arch = args["arch"] +if (arch == "arm32") { + main("armeabi-v7a", arch) +} else if (arch == "arm64") { + main("arm64-v8a", arch) +} else { + console.log("Unsupported architecture: ", arch) + exit(1) } diff --git a/arkoala/framework/native/meson.build b/arkoala/framework/native/meson.build index 83b4cf914..5d33d1c2e 100644 --- a/arkoala/framework/native/meson.build +++ b/arkoala/framework/native/meson.build @@ -240,7 +240,8 @@ else cflags += ['-Wno-parentheses-equality', '-Wno-extern-c-compat'] endif -if get_option('arkoala') and not is_ohos +if get_option('arkoala') and (not is_ohos or arch == 'arm64') + cflags += ['-DLIBACE_' + os.to_upper() + '_' + arch.to_upper()] shared_library(libace_name, libace_sources, override_options: [ diff --git a/arkoala/framework/native/src/generated/library.cc b/arkoala/framework/native/src/generated/library.cc index 84c857d93..e7ef82713 100644 --- a/arkoala/framework/native/src/generated/library.cc +++ b/arkoala/framework/native/src/generated/library.cc @@ -22,17 +22,32 @@ #include "interop-logging.h" #include "arkoala_api_generated.h" +#ifdef LIBACE_OHOS_ARM64 +#include + +static const char LD_LIBRARY_PATH[] = "/data/panda/lib"; +#endif + // TODO: rework for generic OHOS case. void* FindModule(int kind) { std::tuple candidates[] = { +#ifndef LIBACE_OHOS_ARM64 { "ace_compatible", true}, { "ace", true }, +#endif { "ace_compatible_mock", true}, { nullptr, false } }; +#ifndef LIBACE_OHOS_ARM64 char* envValue = getenv("ACE_LIBRARY_PATH"); std::string prefix = envValue ? std::string(envValue) : ""; - LOGE("Search ACE in \"%s\" (env ACE_LIBRARY_PATH) for API %d", prefix.c_str(), kind); +#else + std::string prefix = "/data/storage/el1/bundle/libs/arm64"; + + setenv("LD_LIBRARY_PATH",LD_LIBRARY_PATH, 1); +#endif + + LOGE("Search ACE in \"%s\" for API %d", prefix.c_str(), kind); for (auto* candidate = candidates; std::get<0>(*candidate); candidate++) { std::string name = std::get<0>(*candidate); if (std::get<1>(*candidate)) { @@ -43,10 +58,9 @@ void* FindModule(int kind) { if (module) { LOGE("ACE module at: %s", libraryName.c_str()); return module; - } else { - // LOGE("Cannot find ACE module: %s %s", libraryName.c_str(), libraryError()); } } + LOGE("Cannot find ACE module: %s", libraryError()); return nullptr; } @@ -62,6 +76,10 @@ const GENERATED_ArkUIAnyAPI* GetAnyImpl(int kind, int version, std::string* resu typedef GENERATED_ArkUIAnyAPI* (*GetAPI_t)(int, int); static GetAPI_t getAPI = nullptr; +#ifdef LIBACE_OHOS_ARM64 + char* envValue = nullptr; + #warning "LIBACE_OHOS_ARM64: use FindModule directly" +#else char* envValue = getenv("__LIBACE_ENTRY_POINT"); if (envValue) { long long value = strtoll(envValue, NULL, 16); @@ -69,6 +87,7 @@ const GENERATED_ArkUIAnyAPI* GetAnyImpl(int kind, int version, std::string* resu getAPI = reinterpret_cast(static_cast(value)); } } +#endif if (getAPI == nullptr) { void* module = FindModule(kind); if (!module) { -- Gitee From 9abe1075d4d02b7b00998b80c92029f53f01f761 Mon Sep 17 00:00:00 2001 From: Nikolay Igotti Date: Wed, 4 Dec 2024 09:29:48 +0300 Subject: [PATCH 2/9] Simplfy Arkoala loader --- arkoala/framework/native/meson.build | 26 ++++++++- .../native/src/generated/bridge_custom.cc | 55 +------------------ .../framework/native/src/generated/library.cc | 14 ++++- arkoala/framework/native/src/vsync.cc | 45 +++++++++++++++ interop/src/cpp/vmloader.cc | 4 ++ 5 files changed, 87 insertions(+), 57 deletions(-) create mode 100644 arkoala/framework/native/src/vsync.cc diff --git a/arkoala/framework/native/meson.build b/arkoala/framework/native/meson.build index 5d33d1c2e..fc719a26b 100644 --- a/arkoala/framework/native/meson.build +++ b/arkoala/framework/native/meson.build @@ -24,6 +24,7 @@ libace_sources = [ arkoala_sources = [ './src/events.cc', + './src/vsync.cc', './src/generated/all_events.cc', './src/generated/bridge_generated.cc', './src/generated/callback_deserialize_call.cc', @@ -111,7 +112,7 @@ if os == 'linux' platform_suffix = 'so' endif if os == 'macos' - cflags += ['-DKOALA_MACOS', '-mmacosx-version-min=13.0'] + cflags += ['-DKOALA_MACOS', '-mmacosx-version-min=13.3'] platform_prefix = 'lib' platform_suffix = 'dylib' endif @@ -230,8 +231,6 @@ endif if get_option('arkoala') sources += arkoala_sources -else - library_use_name = 'ArkoalaLoader' endif if is_msvc @@ -274,6 +273,8 @@ shared_library(library_use_name, if get_option('vmloader') == true + + vmloader_cflags = ['-DKOALA_' + os.to_upper(), '-DKOALA_' + os.to_upper() + '_' + arch.to_upper()] vmloader_ldflags = [] @@ -315,4 +316,23 @@ if get_option('vmloader') == true cpp_args: vmloader_cflags, link_args: vmloader_ldflags, ) + + loader_sources = [ + './src/generated/library.cc', + './src/vsync.cc', + interop_src / 'common-interop.cc', + interop_src / 'interop-logging.cc', + ] + + shared_library('ArkoalaLoader', + loader_sources, + install: true, + name_prefix: module_prefix, + name_suffix: module_suffix, + include_directories: include_dirs, + install_dir: source_dir / '..' / 'build', + cpp_args: cflags, + link_args: ldflags, + dependencies: deps + ) endif diff --git a/arkoala/framework/native/src/generated/bridge_custom.cc b/arkoala/framework/native/src/generated/bridge_custom.cc index 1e9263e43..18cb71b60 100644 --- a/arkoala/framework/native/src/generated/bridge_custom.cc +++ b/arkoala/framework/native/src/generated/bridge_custom.cc @@ -26,19 +26,8 @@ #include "arkoala_api_generated.h" #include "Serializers.h" -const GENERATED_ArkUIAnyAPI* GetAnyImpl(int kind, int version, std::string* result = nullptr); - -const GENERATED_ArkUIBasicNodeAPI* GetArkUIBasicNodeAPI() { - return reinterpret_cast( - GetAnyImpl(static_cast(GENERATED_Ark_APIVariantKind::GENERATED_BASIC), - GENERATED_ARKUI_BASIC_NODE_API_VERSION, nullptr)); -} - -const GENERATED_ArkUIExtendedNodeAPI* GetArkUIExtendedNodeAPI() { - return reinterpret_cast( - GetAnyImpl(static_cast(GENERATED_Ark_APIVariantKind::GENERATED_EXTENDED), - GENERATED_ARKUI_EXTENDED_NODE_API_VERSION, nullptr)); -} +const GENERATED_ArkUIBasicNodeAPI* GetArkUIBasicNodeAPI(); +const GENERATED_ArkUIExtendedNodeAPI* GetArkUIExtendedNodeAPI(); CustomDeserializer* DeserializerBase::customDeserializers = nullptr; @@ -343,46 +332,6 @@ void impl_SetLazyItemIndexer(KVMContext vmContext, Ark_NativePointer nodePtr, Ar } KOALA_INTEROP_CTX_V2(SetLazyItemIndexer, Ark_NativePointer, Ark_Int32) -// TODO: map if multiple pipeline contexts. -static KVMDeferred* currentVsyncDeferred = nullptr; - -void vsyncCallback(Ark_PipelineContext context) { - if (currentVsyncDeferred) { - currentVsyncDeferred->resolve(currentVsyncDeferred, nullptr, 0); - currentVsyncDeferred = nullptr; - } -} - -void impl_SetVsyncCallback(Ark_NativePointer pipelineContext) -{ - Ark_PipelineContext pipelineContextCast = (Ark_PipelineContext) pipelineContext; - GetArkUIExtendedNodeAPI()->setVsyncCallback(pipelineContextCast, vsyncCallback); -} -KOALA_INTEROP_V1(SetVsyncCallback, Ark_NativePointer) - -KVMObjectHandle impl_VSyncAwait(KVMContext vmContext, Ark_NativePointer pipelineContext) -{ - Ark_PipelineContext pipelineContextCast = (Ark_PipelineContext)pipelineContext; - KVMObjectHandle result = nullptr; - KVMDeferred* deferred = CreateDeferred(vmContext, &result); - if (currentVsyncDeferred) { - LOGE("%s", "Multiple unresolved vsync deferred"); - currentVsyncDeferred->reject(currentVsyncDeferred, "Wrong"); - } - currentVsyncDeferred = deferred; - return result; -} -KOALA_INTEROP_CTX_1(VSyncAwait, KVMObjectHandle, Ark_NativePointer) - -void impl_UnblockVsyncWait(Ark_NativePointer pipelineContext) -{ - if (currentVsyncDeferred) { - currentVsyncDeferred->resolve(currentVsyncDeferred, nullptr, 0); - currentVsyncDeferred = nullptr; - } -} -KOALA_INTEROP_V1(UnblockVsyncWait, Ark_NativePointer) - void impl_SetCustomCallback(KVMContext vmContext, Ark_NativePointer nodePtr, Ark_Int32 updaterId) { Ark_VMContext vmContextCast = (Ark_VMContext) vmContext; diff --git a/arkoala/framework/native/src/generated/library.cc b/arkoala/framework/native/src/generated/library.cc index e7ef82713..8f8c8f560 100644 --- a/arkoala/framework/native/src/generated/library.cc +++ b/arkoala/framework/native/src/generated/library.cc @@ -134,4 +134,16 @@ const GENERATED_ArkUIAnyAPI* GetAnyImpl(int kind, int version, std::string* resu impls[kind] = impl; } return impls[kind]; -} \ No newline at end of file +} + +const GENERATED_ArkUIBasicNodeAPI* GetArkUIBasicNodeAPI() { + return reinterpret_cast( + GetAnyImpl(static_cast(GENERATED_Ark_APIVariantKind::GENERATED_BASIC), + GENERATED_ARKUI_BASIC_NODE_API_VERSION, nullptr)); +} + +const GENERATED_ArkUIExtendedNodeAPI* GetArkUIExtendedNodeAPI() { + return reinterpret_cast( + GetAnyImpl(static_cast(GENERATED_Ark_APIVariantKind::GENERATED_EXTENDED), + GENERATED_ARKUI_EXTENDED_NODE_API_VERSION, nullptr)); +} diff --git a/arkoala/framework/native/src/vsync.cc b/arkoala/framework/native/src/vsync.cc new file mode 100644 index 000000000..db4fed199 --- /dev/null +++ b/arkoala/framework/native/src/vsync.cc @@ -0,0 +1,45 @@ +#include "common-interop.h" +#include "interop-logging.h" + +#include "arkoala_api_generated.h" + +const GENERATED_ArkUIExtendedNodeAPI* GetArkUIExtendedNodeAPI(); + +// TODO: map if multiple pipeline contexts. +static KVMDeferred* currentVsyncDeferred = nullptr; + +void vsyncCallback(Ark_PipelineContext context) { + if (currentVsyncDeferred) { + currentVsyncDeferred->resolve(currentVsyncDeferred, nullptr, 0); + currentVsyncDeferred = nullptr; + } +} + +void impl_SetVsyncCallback(Ark_NativePointer pipelineContext) { + Ark_PipelineContext pipelineContextCast = (Ark_PipelineContext) pipelineContext; + GetArkUIExtendedNodeAPI()->setVsyncCallback(pipelineContextCast, vsyncCallback); +} +KOALA_INTEROP_V1(SetVsyncCallback, Ark_NativePointer) + +KVMObjectHandle impl_VSyncAwait(KVMContext vmContext, Ark_NativePointer pipelineContext) +{ + Ark_PipelineContext pipelineContextCast = (Ark_PipelineContext)pipelineContext; + KVMObjectHandle result = nullptr; + KVMDeferred* deferred = CreateDeferred(vmContext, &result); + if (currentVsyncDeferred) { + LOGE("%s", "Multiple unresolved vsync deferred"); + currentVsyncDeferred->reject(currentVsyncDeferred, "Wrong"); + } + currentVsyncDeferred = deferred; + return result; +} +KOALA_INTEROP_CTX_1(VSyncAwait, KVMObjectHandle, Ark_NativePointer) + +void impl_UnblockVsyncWait(Ark_NativePointer pipelineContext) +{ + if (currentVsyncDeferred) { + currentVsyncDeferred->resolve(currentVsyncDeferred, nullptr, 0); + currentVsyncDeferred = nullptr; + } +} +KOALA_INTEROP_V1(UnblockVsyncWait, Ark_NativePointer) diff --git a/interop/src/cpp/vmloader.cc b/interop/src/cpp/vmloader.cc index 8430ab5a5..1044e6394 100644 --- a/interop/src/cpp/vmloader.cc +++ b/interop/src/cpp/vmloader.cc @@ -428,6 +428,10 @@ extern "C" DLL_EXPORT void EmitEvent(const KInt type, const KInt target, const K #ifdef KOALA_JNI if (g_vmEntry.vmKind == JAVA_VM_KIND) { JNIEnv* jEnv = (JNIEnv*)(g_vmEntry.env); + if (!g_vmEntry.emitEvent) { + LOG("#### Cannot find emitEvent method"); + return; + } jEnv->CallVoidMethod( (jobject)(g_vmEntry.app), (jmethodID)(g_vmEntry.emitEvent), -- Gitee From 4621b5c70485a17107a8f8332b2d43a8c4759bd3 Mon Sep 17 00:00:00 2001 From: Nikolay Igotti Date: Wed, 4 Dec 2024 09:44:29 +0300 Subject: [PATCH 3/9] Fix Darwin build --- arkoala/framework/native/meson.build | 15 +++++++++++++-- arkoala/framework/package.json | 2 +- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/arkoala/framework/native/meson.build b/arkoala/framework/native/meson.build index fc719a26b..601fb83a2 100644 --- a/arkoala/framework/native/meson.build +++ b/arkoala/framework/native/meson.build @@ -180,6 +180,9 @@ if is_jni if jni_os_dir == 'windows' jni_os_dir = 'win32' endif + if jni_os_dir == 'macos' + jni_os_dir = 'darwin' + endif include_dirs += [ interop_src / 'jni', interop_src / 'types', @@ -273,8 +276,6 @@ shared_library(library_use_name, if get_option('vmloader') == true - - vmloader_cflags = ['-DKOALA_' + os.to_upper(), '-DKOALA_' + os.to_upper() + '_' + arch.to_upper()] vmloader_ldflags = [] @@ -324,8 +325,18 @@ if get_option('vmloader') == true interop_src / 'interop-logging.cc', ] + if is_napi + loader_sources += [ + interop_src / 'napi/convertors-napi.cc', + ] + endif + shared_library('ArkoalaLoader', loader_sources, + override_options: [ + # So that we can refer NAPI symbols. + 'b_lundef=false', + ], install: true, name_prefix: module_prefix, name_suffix: module_suffix, diff --git a/arkoala/framework/package.json b/arkoala/framework/package.json index 9b7843d47..11410c073 100644 --- a/arkoala/framework/package.json +++ b/arkoala/framework/package.json @@ -33,7 +33,7 @@ "compile:native-hzvm-host": "npm run configure:native-hzvm-host && cd native && meson compile -C build-hzvm-host && meson install -C build-hzvm-host", "configure:native-panda-host": "cd native && meson setup -D vm_kind=panda build-panda-host", "compile:native-panda-host": "npm run configure:native-panda-host && cd native && meson compile -C build-panda-host && meson install -C build-panda-host", - "configure:native-jvm-host": "cd native && meson setup -D vm_kind=jvm build-jvm-host -D jdk_dir=$JAVA_HOME", + "configure:native-jvm-host": "cd native && meson setup -D vm_kind=jvm build-jvm-host -D vmloader=true -D jdk_dir=$JAVA_HOME", "compile:native-jvm-host": "npm run configure:native-jvm-host && cd native && meson compile -C build-jvm-host && meson install -C build-jvm-host", "configure:native-hzvm-ohos-arm64": "npm run prepare:arm64 && cd native && node ../scripts/configure.mjs hzvm-ohos-arm64", "compile:native-hzvm-ohos-arm64": "npm run configure:native-hzvm-ohos-arm64 && cd native && meson compile -C build-hzvm-ohos-arm64 && meson install -C build-hzvm-ohos-arm64", -- Gitee From 5b0a0ec54f29c38d14037573e052f5b3aa227197 Mon Sep 17 00:00:00 2001 From: Nikolay Igotti Date: Wed, 4 Dec 2024 11:05:20 +0300 Subject: [PATCH 4/9] Move GetPipelineContext() Signed-off-by: Nikolay Igotti --- arkoala/framework/native/src/generated/bridge_custom.cc | 7 ------- arkoala/framework/native/src/vsync.cc | 7 +++++++ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/arkoala/framework/native/src/generated/bridge_custom.cc b/arkoala/framework/native/src/generated/bridge_custom.cc index 18cb71b60..08b59ff86 100644 --- a/arkoala/framework/native/src/generated/bridge_custom.cc +++ b/arkoala/framework/native/src/generated/bridge_custom.cc @@ -417,13 +417,6 @@ void impl_SetRangeUpdater(Ark_NativePointer nodePtr, Ark_Int32 updaterId) } KOALA_INTEROP_V2(SetRangeUpdater, Ark_NativePointer, Ark_Int32) -Ark_NativePointer impl_GetPipelineContext(Ark_NativePointer nodePtr) -{ - Ark_NodeHandle nodePtrCast = (Ark_NodeHandle) nodePtr; - return GetArkUIExtendedNodeAPI()->getPipelineContext(nodePtrCast); -} -KOALA_INTEROP_1(GetPipelineContext, Ark_NativePointer, Ark_NativePointer) - void impl_SetChildTotalCount(Ark_NativePointer nodePtr, Ark_Int32 totalCount) { Ark_NodeHandle nodePtrCast = (Ark_NodeHandle) nodePtr; diff --git a/arkoala/framework/native/src/vsync.cc b/arkoala/framework/native/src/vsync.cc index db4fed199..6e977e726 100644 --- a/arkoala/framework/native/src/vsync.cc +++ b/arkoala/framework/native/src/vsync.cc @@ -43,3 +43,10 @@ void impl_UnblockVsyncWait(Ark_NativePointer pipelineContext) } } KOALA_INTEROP_V1(UnblockVsyncWait, Ark_NativePointer) + +Ark_NativePointer impl_GetPipelineContext(Ark_NativePointer nodePtr) +{ + Ark_NodeHandle nodePtrCast = (Ark_NodeHandle) nodePtr; + return GetArkUIExtendedNodeAPI()->getPipelineContext(nodePtrCast); +} +KOALA_INTEROP_1(GetPipelineContext, Ark_NativePointer, Ark_NativePointer) -- Gitee From 3c3c4c8f11444dc02c8fc5096ae206686c6e1670 Mon Sep 17 00:00:00 2001 From: Kirill Kirichenko Date: Thu, 5 Dec 2024 16:24:09 +0300 Subject: [PATCH 5/9] More fixes. Workable version. Bulk logging disabled Signed-off-by: Kirill Kirichenko --- arkoala-arkts/arkui/src/Application.ts | 2 +- .../har/arkoala-har-bundle/loader.js | 4 +- .../har/arkoala-har-bundle/rollup.config.mjs | 3 +- .../har/scripts/build-arkoala-har.mjs | 34 +++++++---- arkoala/framework/native/meson.build | 1 + .../framework/native/src/generated/library.cc | 18 ++---- interop/src/cpp/vmloader.cc | 61 ++++++++++--------- 7 files changed, 66 insertions(+), 57 deletions(-) diff --git a/arkoala-arkts/arkui/src/Application.ts b/arkoala-arkts/arkui/src/Application.ts index 48f3d71e8..e4cb55a87 100644 --- a/arkoala-arkts/arkui/src/Application.ts +++ b/arkoala-arkts/arkui/src/Application.ts @@ -173,7 +173,7 @@ export class Application { callScheduledCallbacks() } - withLog = true + withLog = false updateStates(manager: StateManager, root: ComputableState) { // Ensure all current state updates took effect. diff --git a/arkoala-arkts/har/arkoala-har-bundle/loader.js b/arkoala-arkts/har/arkoala-har-bundle/loader.js index a8bda75ed..eae927a69 100644 --- a/arkoala-arkts/har/arkoala-har-bundle/loader.js +++ b/arkoala-arkts/har/arkoala-har-bundle/loader.js @@ -94,8 +94,8 @@ export async function runEventLoop() { } export function checkLoader(variant) { let vm = -1; - let classPath = "/data/storage/el1/bundle/libs/arm" - let nativePath = "/data/storage/el1/bundle/libs/arm" + let classPath = `/data/storage/el1/bundle/libs/__ARCH__` + let nativePath = `/data/storage/el1/bundle/libs/__ARCH__` switch (variant) { case 'panda': { vm = 2; diff --git a/arkoala-arkts/har/arkoala-har-bundle/rollup.config.mjs b/arkoala-arkts/har/arkoala-har-bundle/rollup.config.mjs index 09de10efa..0c3d31151 100644 --- a/arkoala-arkts/har/arkoala-har-bundle/rollup.config.mjs +++ b/arkoala-arkts/har/arkoala-har-bundle/rollup.config.mjs @@ -31,7 +31,7 @@ const DEBUG = true; //const implementedPackagesEntries = implementedPackages.map((name) => `@koalaui/arkoala-arkui/${name}`) /** @type {import("rollup").RollupOptions[]} */ -export default [{ +export default cliOptions => [{ input: ["./bundle.mjs" /*, ...implementedPackagesEntries*/], output: { format: "module", @@ -59,6 +59,7 @@ export default [{ preventAssignment: true, values: { __ARKOALA_HAR__: 'true', + __ARCH__: cliOptions.arch } }), inject({ diff --git a/arkoala-arkts/har/scripts/build-arkoala-har.mjs b/arkoala-arkts/har/scripts/build-arkoala-har.mjs index 733ec1e44..7b0e82ef7 100644 --- a/arkoala-arkts/har/scripts/build-arkoala-har.mjs +++ b/arkoala-arkts/har/scripts/build-arkoala-har.mjs @@ -19,12 +19,12 @@ function execCmdSync(cmd, options) { return execSync(cmd, options).toString().trim().replace("\n", " ") } -function rollupLaunch() { +function rollupLaunch(loaderArch) { console.log(`> Run rollup`) - execCmdSync("npx rollup -c") + execCmdSync(`npx rollup -c --arch ${loaderArch}`) } -function copyFilesToHar(from, to) { +function copyFileToHar(from, to) { if (!fs.existsSync(from)) { throw new Error(`file ${from} does not exist`) } @@ -33,26 +33,36 @@ function copyFilesToHar(from, to) { fs.cpSync(from, to, { recursive: true, force: true }) } +function copySoLibs(from, to) { + fs.readdirSync(from, {withFileTypes: true}) + .filter(file => file.name.endsWith(".so")) + .forEach(file => { + console.log(`> Copy from: ${from}/${file.name} to ${to}/${file.name}`) + fs.cpSync(`${from}/${file.name}`, `${to}/${file.name}`, { recursive: true, force: true }) + }) +} -function main(targetLibDir) { +function main(targetLibDir, loaderArch) { process.chdir(BUNDLE_PATH) - rollupLaunch() + rollupLaunch(loaderArch) /* we don't yet know which files should be in har */ - copyFilesToHar(path.join(_dirname, `../../../arkoala/framework/build/libc++.so`), path.join(HAR_PATH, `libs/${targetLibDir}/libc++.so`)) - copyFilesToHar(path.join(_dirname, `../../../arkoala/framework/build/libArkoalaLoader.so`), path.join(HAR_PATH, `libs/${targetLibDir}/libArkoalaLoader.so`)) - copyFilesToHar(path.join(_dirname, `../../../arkoala/framework/build/libvmloader.so`), path.join(HAR_PATH, `libs/${targetLibDir}/libvmloader.so`)) - copyFilesToHar(path.join(_dirname, `../../../arkoala/framework/build/libArkoalaNative_ark.so`), path.join(HAR_PATH, `libs/${targetLibDir}/libArkoalaNative_ark.so`)) - copyFilesToHar(path.join(_dirname, `../../build/arkoala.abc`), path.join(HAR_PATH, `libs/${targetLibDir}/arkoala.abc.so`)) + copyFileToHar(path.join(_dirname, `../../../arkoala/framework/build/libc++.so`), path.join(HAR_PATH, `libs/${targetLibDir}/libc++.so`)) + copyFileToHar(path.join(_dirname, `../../../arkoala/framework/build/libArkoalaLoader.so`), path.join(HAR_PATH, `libs/${targetLibDir}/libArkoalaLoader.so`)) + copyFileToHar(path.join(_dirname, `../../../arkoala/framework/build/libvmloader.so`), path.join(HAR_PATH, `libs/${targetLibDir}/libvmloader.so`)) + copyFileToHar(path.join(_dirname, `../../../arkoala/framework/build/libArkoalaNative_ark.so`), path.join(HAR_PATH, `libs/${targetLibDir}/libArkoalaNative_ark.so`)) + copyFileToHar(path.join(_dirname, `../../build/arkoala.abc`), path.join(HAR_PATH, `libs/${targetLibDir}/arkoala.abc.so`)) } const arch = args["arch"] if (arch == "arm32") { - main("armeabi-v7a", arch) + main("armeabi-v7a", "arm") } else if (arch == "arm64") { main("arm64-v8a", arch) - copyFilesToHar(path.join(_dirname, `../../../arkoala/framework/build/libace_compatible_mock.so`), path.join(HAR_PATH, `libs/arm64-v8a/libace_compatible_mock.so`)) + copyFileToHar(path.join(_dirname, `../../../arkoala/framework/build/libace_compatible_mock.so`), path.join(HAR_PATH, `libs/arm64-v8a/libace_compatible_mock.so`)) + copyFileToHar(path.join(_dirname, `../../../incremental/tools/panda/node_modules/@panda/sdk/ets/etsstdlib.abc`), path.join(HAR_PATH, `libs/arm64-v8a/etsstdlib.abc.so`)) + copySoLibs(path.join(_dirname, `../../../incremental/tools/panda/node_modules/@panda/sdk/ohos_arm64/lib`), path.join(HAR_PATH, `libs/arm64-v8a`)) } else { console.log("Unsupported architecture: ", arch) exit(1) diff --git a/arkoala/framework/native/meson.build b/arkoala/framework/native/meson.build index 601fb83a2..7129467aa 100644 --- a/arkoala/framework/native/meson.build +++ b/arkoala/framework/native/meson.build @@ -331,6 +331,7 @@ if get_option('vmloader') == true ] endif + cflags += ['-DLIBACE_' + os.to_upper() + '_' + arch.to_upper()] shared_library('ArkoalaLoader', loader_sources, override_options: [ diff --git a/arkoala/framework/native/src/generated/library.cc b/arkoala/framework/native/src/generated/library.cc index 8f8c8f560..ce67c771e 100644 --- a/arkoala/framework/native/src/generated/library.cc +++ b/arkoala/framework/native/src/generated/library.cc @@ -22,12 +22,6 @@ #include "interop-logging.h" #include "arkoala_api_generated.h" -#ifdef LIBACE_OHOS_ARM64 -#include - -static const char LD_LIBRARY_PATH[] = "/data/panda/lib"; -#endif - // TODO: rework for generic OHOS case. void* FindModule(int kind) { std::tuple candidates[] = { @@ -43,11 +37,9 @@ void* FindModule(int kind) { std::string prefix = envValue ? std::string(envValue) : ""; #else std::string prefix = "/data/storage/el1/bundle/libs/arm64"; - - setenv("LD_LIBRARY_PATH",LD_LIBRARY_PATH, 1); #endif - LOGE("Search ACE in \"%s\" for API %d", prefix.c_str(), kind); + LOGE("Search ACE in \"%" LOG_PUBLIC "s\" for API %" LOG_PUBLIC "d", prefix.c_str(), kind); for (auto* candidate = candidates; std::get<0>(*candidate); candidate++) { std::string name = std::get<0>(*candidate); if (std::get<1>(*candidate)) { @@ -56,11 +48,11 @@ void* FindModule(int kind) { std::string libraryName = prefix + "/" + name; void* module = loadLibrary(libraryName); if (module) { - LOGE("ACE module at: %s", libraryName.c_str()); + LOGE("ACE module at: %" LOG_PUBLIC "s module = %" LOG_PUBLIC "p", libraryName.c_str(), module); return module; } } - LOGE("Cannot find ACE module: %s", libraryError()); + LOGE("Cannot find ACE module: %" LOG_PUBLIC "s", libraryError()); return nullptr; } @@ -102,7 +94,7 @@ const GENERATED_ArkUIAnyAPI* GetAnyImpl(int kind, int version, std::string* resu if (result) *result = std::string("Cannot find ") + getArkAnyAPIFuncName; else - LOGE("Cannot find %s", getArkAnyAPIFuncName); + LOGE("Cannot find %" LOG_PUBLIC "s", getArkAnyAPIFuncName); return nullptr; } } @@ -117,7 +109,7 @@ const GENERATED_ArkUIAnyAPI* GetAnyImpl(int kind, int version, std::string* resu if (result) *result = "getAPI() returned null"; else - LOG("getAPI() returned null") + LOGE("getAPI() returned null for kind=%" LOG_PUBLIC "d, version=%" LOG_PUBLIC "d", kind, version); return nullptr; } if (impl->version != version) { diff --git a/interop/src/cpp/vmloader.cc b/interop/src/cpp/vmloader.cc index 1044e6394..a557960ed 100644 --- a/interop/src/cpp/vmloader.cc +++ b/interop/src/cpp/vmloader.cc @@ -63,38 +63,48 @@ const VMLibInfo javaVMLib = { #ifdef KOALA_ETS_NAPI const VMLibInfo pandaVMLib = { + // sdkPath #if defined(KOALA_OHOS) - #if defined(__arm) - "/system" - #else - "/data/storage/el1/bundle/libs/arm64" - #endif + #if defined(__arm) + "/system" + #else + "/data/storage/el1/bundle/libs" + #endif #else - getenv("PANDA_HOME") + getenv("PANDA_HOME") #endif , + + // platform #ifdef KOALA_LINUX - #ifdef KOALA_LINUX_ARM64 - "linux_arm64_host_tools/lib" - #else - "linux_host_tools/lib" - #endif + #ifdef KOALA_LINUX_ARM64 + "linux_arm64_host_tools/lib" + #else + "linux_host_tools/lib" + #endif #elif KOALA_MACOS - "macos_host_tools/lib" + "macos_host_tools/lib" #elif KOALA_WINDOWS - "_host_tools/lib" - #elif KOALA_OHOS - "ohos_arm64/lib" + "_host_tools/lib" + #elif KOALA_OHOS_ARM64 + "arm64" + #elif KOALA_OHOS_ARM32 + "arm" #else - #error "Unknown platform" + #error "Unknown platform" #endif , + + // lib #if defined(__arm) - "etsnative.z", + "etsnative.z" #else - "arkruntime", + "arkruntime" #endif - "ETS_CreateVM", + , + + // createVM + "ETS_CreateVM" }; #endif @@ -159,9 +169,9 @@ extern "C" DLL_EXPORT KInt LoadVirtualMachine(KInt vmKind, const char* appClassP LOGI("Starting VM %" LOG_PUBLIC "d with classpath=%" LOG_PUBLIC "s native=%" LOG_PUBLIC "s", vmKind, appClassPath, appLibPath); std::string libPath = -#if defined(KOALA_LINUX) || defined(KOALA_MACOS) || defined(KOALA_WINDOWS) +#if defined(KOALA_LINUX) || defined(KOALA_MACOS) || defined(KOALA_WINDOWS) || defined (KOALA_OHOS_ARM64) std::string(thisVM->sdkPath) + "/" + std::string(thisVM->platform) + "/" + libName(thisVM->lib) -#elif defined(KOALA_OHOS) +#elif defined(KOALA_OHOS_ARM32) libName(thisVM->lib) #else #error "Library path not specified for this platform" @@ -211,13 +221,8 @@ extern "C" DLL_EXPORT KInt LoadVirtualMachine(KInt vmKind, const char* appClassP traverseDir(std::string(appClassPath), files); std::sort(files.begin(), files.end()); etsVMOptions = { -#if defined(KOALA_LINUX) +#if defined(KOALA_LINUX) || defined(KOALA_OHOS_ARM32) {EtsOptionType::ETS_BOOT_FILE, (char*)strdup((std::string(thisVM->sdkPath) + "/ets/etsstdlib.abc").c_str())}, -#endif -#if defined(KOALA_OHOS) -#if defined(__arm) || defined(__aarch64__) - {EtsOptionType::ETS_BOOT_FILE, (char*)strdup((std::string(thisVM->sdkPath) + "/etc/etsstdlib.abc").c_str())}, -#endif #endif }; for (const std::string& path : files) { @@ -294,7 +299,7 @@ extern "C" DLL_EXPORT KNativePointer StartApplication(const char* appUrl, const return nullptr; } - LOGI("#### Starting app %" LOG_PUBLIC "s with params %" LOG_PUBLIC "s", appUrl, appParams); + LOGI("Starting app %" LOG_PUBLIC "s with params %" LOG_PUBLIC "s", appUrl, appParams); #ifdef KOALA_JNI if (g_vmEntry.vmKind == JAVA_VM_KIND) { -- Gitee From 71166c935368ae8bf868a449a620ae51b7c08e61 Mon Sep 17 00:00:00 2001 From: guozejun Date: Mon, 16 Dec 2024 17:32:09 +0800 Subject: [PATCH 6/9] workaround fix for callback --- arkoala-arkts/arkui/src/Application.ts | 28 ++++++++++--------- arkoala-arkts/arkui/src/generated/Events.ts | 1 + .../peers/CallbackDeserializeCall.ts | 11 +++++++- .../src/generated/peers/CallbacksChecker.ts | 1 + arkoala/framework/native/src/callbacks.cc | 4 +++ .../src/generated/callback_managed_caller.cc | 1 + .../framework/native/src/generated/library.cc | 3 -- 7 files changed, 32 insertions(+), 17 deletions(-) diff --git a/arkoala-arkts/arkui/src/Application.ts b/arkoala-arkts/arkui/src/Application.ts index e4cb55a87..d21da5f7a 100644 --- a/arkoala-arkts/arkui/src/Application.ts +++ b/arkoala-arkts/arkui/src/Application.ts @@ -97,10 +97,10 @@ function dumpTree(node: IncrementalNode, indent: int32 = 0) { return str } - if (indent == 0) console.log("> Dump tree:") + // if (indent == 0) // console.log("> Dump tree:") let child = node.firstChild - console.log("> " + indentToString(indent++) + "| " + node) + // console.log("> " + indentToString(indent++) + "| " + node) while (child) { dumpTree(child!, indent + 1) @@ -113,7 +113,7 @@ function drawCurrentCrash(crash: Object) { let msg = crash.toString() + "\n" if (Object.hasOwn(crash, "stack")) msg += (crash as Error).stack if (!crashDumped) { - console.log(msg) + // console.log(msg) crashDumped = true } NativeModule._ShowCrash(msg ?? "unknown error message") @@ -153,18 +153,18 @@ export class Application { if (this.withLog) { UserView.stopNativeLog(1) let log = UserView.getNativeLog(1) - if (log.length > 0) console.log(log) + // if (log.length > 0) // console.log(log) } return rootPointer! } private checkEvents(what: int32) { - console.log("ARKTS: checkEvents") + // console.log("ARKTS: checkEvents") checkEvents() } private updateState() { - console.log("ARKTS: updateState") + // console.log("ARKTS: updateState") this.updateStates(this.manager!, this.root!) // Here we request to draw a frame and call custom components JS callbacks. @@ -195,7 +195,7 @@ export class Application { try { root.value } catch (error) { - console.log('has error in partialUpdates') + // console.log('has error in partialUpdates') } // Notify subscriber. update.callback(false) @@ -209,7 +209,7 @@ export class Application { private render() { - console.log("ARKTS: render") + // console.log("ARKTS: render") } enter(arg0: int32, arg1: int32): boolean { @@ -225,7 +225,7 @@ export class Application { } catch (error) { if (error instanceof Error) { if (error.stack) { - console.log(error.stack) + // console.log(error.stack) return true } } @@ -235,13 +235,14 @@ export class Application { if (this.withLog) { UserView.stopNativeLog(1) let log = UserView.getNativeLog(1) - if (log.length > 0) console.log(log) + // if (log.length > 0) // console.log(log) } return this.exitApp } loopIteration(arg0: int32, arg1: int32) { - console.log("ARKTS: loopIteration") + NativeModule._NativeLog("testtest ARKTS: loopIteration") + // step4 this.checkEvents(arg0) this.updateState() this.render() @@ -259,7 +260,7 @@ export class Application { break } case EventType.Text.valueOf(): { - console.log("ARKTS: [emitEvent] EventType.Text is not implemented." + type) + // console.log("ARKTS: [emitEvent] EventType.Text is not implemented." + type) break } case EventType.ExitApp.valueOf(): { @@ -267,7 +268,7 @@ export class Application { break } default: { - console.log("ARKTS: [emitEvent] type = " + type + " is unknown.") + // console.log("ARKTS: [emitEvent] type = " + type + " is unknown.") break } } @@ -276,6 +277,7 @@ export class Application { } static createApplication(appUrl: string, params: string): Application { + NativeModule._NativeLog("testtest createApplication View"+appUrl) const userView = NativeModule._LoadUserView("View" + appUrl, params) if (userView == undefined) throw new Error("Cannot load user view"); return new Application(userView as UserView) diff --git a/arkoala-arkts/arkui/src/generated/Events.ts b/arkoala-arkts/arkui/src/generated/Events.ts index b8e37c8e5..025ad3e43 100644 --- a/arkoala-arkts/arkui/src/generated/Events.ts +++ b/arkoala-arkts/arkui/src/generated/Events.ts @@ -14,6 +14,7 @@ */ export function checkEvents() { + // step5 customEventsChecker() } diff --git a/arkoala-arkts/arkui/src/generated/peers/CallbackDeserializeCall.ts b/arkoala-arkts/arkui/src/generated/peers/CallbackDeserializeCall.ts index 5b7dc8f8e..f7bbf95a6 100644 --- a/arkoala-arkts/arkui/src/generated/peers/CallbackDeserializeCall.ts +++ b/arkoala-arkts/arkui/src/generated/peers/CallbackDeserializeCall.ts @@ -218,6 +218,8 @@ import { IPropertySubscriber } from "./../ArkIPropertySubscriberMaterialized" import { Matrix2D } from "./../ArkMatrix2DMaterialized" import { Path2D } from "./../ArkPath2DMaterialized" +import { NativeModule } from "#components" + export function deserializeAndCallAccessibilityCallback(thisDeserializer: Deserializer) { const _resourceId : int32 = thisDeserializer.readInt32() const _call = (ResourceHolder.instance().get(_resourceId) as AccessibilityCallback) @@ -365,9 +367,14 @@ export function deserializeAndCallCallback_ClickEvent_SaveButtonOnClickResult_Vo _call(event, result) } export function deserializeAndCallCallback_ClickEvent_Void(thisDeserializer: Deserializer) { + // step xx + NativeModule._NativeLog("testtest deserializeAndCallCallback_ClickEvent_Void 1"); const _resourceId : int32 = thisDeserializer.readInt32() + NativeModule._NativeLog("testtest deserializeAndCallCallback_ClickEvent_Void 2 " + _resourceId); const _call = (ResourceHolder.instance().get(_resourceId) as Function1) - let event : ClickEvent = thisDeserializer.readClickEvent() + NativeModule._NativeLog("testtest deserializeAndCallCallback_ClickEvent_Void 3"); + let event : ClickEvent = {displayX:0, displayY:0, windowX:0, windowY:0 , screenX:0, screenY:0, x:0, y:0, target: {area: {position: {}, globalPosition: {}, width:0, height:0}}, source: SourceType.UNKNOWN, preventDefault: () => {}, timestamp:0, pressure: 0,tiltX:0, tiltY: 0, sourceTool:SourceTool.UNKNOWN} + NativeModule._NativeLog("testtest deserializeAndCallCallback_ClickEvent_Void 4 X: " + event.screenX + " Y: " + event.screenY); _call(event) } export function deserializeAndCallCallback_ComputedBarAttribute_Void(thisDeserializer: Deserializer) { @@ -2023,6 +2030,8 @@ export function deserializeAndCallWithThemeInterface(thisDeserializer: Deseriali } export function deserializeAndCallCallback(thisDeserializer: Deserializer) { const kind : int32 = thisDeserializer.readInt32() + // step6 kind + NativeModule._NativeLog("testtest deserializeAndCallCallback " + kind); switch (kind) { case 0/*CallbackKind.Kind_AccessibilityCallback*/: return deserializeAndCallAccessibilityCallback(thisDeserializer); case 1/*CallbackKind.Kind_ButtonTriggerClickCallback*/: return deserializeAndCallButtonTriggerClickCallback(thisDeserializer); diff --git a/arkoala-arkts/arkui/src/generated/peers/CallbacksChecker.ts b/arkoala-arkts/arkui/src/generated/peers/CallbacksChecker.ts index 861a5eefc..70cf29149 100644 --- a/arkoala-arkts/arkui/src/generated/peers/CallbacksChecker.ts +++ b/arkoala-arkts/arkui/src/generated/peers/CallbacksChecker.ts @@ -15,6 +15,7 @@ const buffer = new KBuffer(bufferSize) const deserializer = new Deserializer(buffer.buffer, bufferSize) export function checkArkoalaCallbacks() { while (true) { + // step6 deserializer.resetCurrentPosition() let result = nativeModule()._CheckArkoalaCallbackEvent(buffer.buffer, bufferSize) if (result == 0) break diff --git a/arkoala/framework/native/src/callbacks.cc b/arkoala/framework/native/src/callbacks.cc index 69352af20..e1f8d6c60 100644 --- a/arkoala/framework/native/src/callbacks.cc +++ b/arkoala/framework/native/src/callbacks.cc @@ -19,6 +19,8 @@ #include "common-interop.h" #include "Serializers.h" +#include "interop-logging.h" + enum CallbackEventKind { Event_CallCallback = 0, Event_HoldManagedResource = 1, @@ -82,6 +84,8 @@ void impl_HoldArkoalaResource(Ark_Int32 resourceId) { KOALA_INTEROP_V1(HoldArkoalaResource, KInt) void enqueueArkoalaCallback(const CallbackBuffer* event) { + // step3 + LOGE0("testtest enqueueArkoalaCallback"); callbackEventsQueue.push_back(Event_CallCallback); callbackCallSubqueue.push_back(*event); } diff --git a/arkoala/framework/native/src/generated/callback_managed_caller.cc b/arkoala/framework/native/src/generated/callback_managed_caller.cc index b121707c7..6764d478c 100644 --- a/arkoala/framework/native/src/generated/callback_managed_caller.cc +++ b/arkoala/framework/native/src/generated/callback_managed_caller.cc @@ -258,6 +258,7 @@ void callManagedCallback_ClickEvent_SaveButtonOnClickResult_Void(Ark_Int32 resou } void callManagedCallback_ClickEvent_Void(Ark_Int32 resourceId, Ark_ClickEvent event) { + // step2 CallbackBuffer __buffer = {{}, {}}; const Ark_CallbackResource __callbackResource = {resourceId, holdManagedCallbackResource, releaseManagedCallbackResource}; __buffer.resourceHolder.holdCallbackResource(&__callbackResource); diff --git a/arkoala/framework/native/src/generated/library.cc b/arkoala/framework/native/src/generated/library.cc index ce67c771e..58e7067de 100644 --- a/arkoala/framework/native/src/generated/library.cc +++ b/arkoala/framework/native/src/generated/library.cc @@ -69,9 +69,6 @@ const GENERATED_ArkUIAnyAPI* GetAnyImpl(int kind, int version, std::string* resu static GetAPI_t getAPI = nullptr; #ifdef LIBACE_OHOS_ARM64 - char* envValue = nullptr; - #warning "LIBACE_OHOS_ARM64: use FindModule directly" -#else char* envValue = getenv("__LIBACE_ENTRY_POINT"); if (envValue) { long long value = strtoll(envValue, NULL, 16); -- Gitee From f1e56c2e45e3aa404b23908182c8b349d8da7512 Mon Sep 17 00:00:00 2001 From: guozejun Date: Mon, 16 Dec 2024 17:32:40 +0800 Subject: [PATCH 7/9] workaround fix for shopping --- arkoala-arkts/arkui/src/generated/peers/ArkUINodeType.ts | 1 + arkoala/framework/native/src/generated/arkoala_api_generated.h | 2 +- arkoala/framework/native/src/generated/bridge_custom.cc | 3 ++- interop/src/cpp/vmloader.cc | 3 +++ 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/arkoala-arkts/arkui/src/generated/peers/ArkUINodeType.ts b/arkoala-arkts/arkui/src/generated/peers/ArkUINodeType.ts index de59645e6..9604c35fc 100644 --- a/arkoala-arkts/arkui/src/generated/peers/ArkUINodeType.ts +++ b/arkoala-arkts/arkui/src/generated/peers/ArkUINodeType.ts @@ -44,6 +44,7 @@ export enum ArkUINodeType { Image, ImageAnimator, ImageSpan, + IndicatorComponent, Line, LinearIndicator, List, diff --git a/arkoala/framework/native/src/generated/arkoala_api_generated.h b/arkoala/framework/native/src/generated/arkoala_api_generated.h index 292b317ae..38f177cab 100644 --- a/arkoala/framework/native/src/generated/arkoala_api_generated.h +++ b/arkoala/framework/native/src/generated/arkoala_api_generated.h @@ -23,7 +23,7 @@ // The only include allowed in this file! Do not add anything else ever. #include -#define GENERATED_ARKUI_FULL_API_VERSION 104 +#define GENERATED_ARKUI_FULL_API_VERSION 105 #define GENERATED_ARKUI_NODE_API_VERSION GENERATED_ARKUI_FULL_API_VERSION #define GENERATED_ARKUI_BASIC_NODE_API_VERSION 1 diff --git a/arkoala/framework/native/src/generated/bridge_custom.cc b/arkoala/framework/native/src/generated/bridge_custom.cc index 08b59ff86..18a71a343 100644 --- a/arkoala/framework/native/src/generated/bridge_custom.cc +++ b/arkoala/framework/native/src/generated/bridge_custom.cc @@ -471,8 +471,9 @@ KVMObjectHandle impl_LoadUserView(KVMContext vm, const KStringPtr& viewClass, co EtsEnv* env = reinterpret_cast(vm); std:: string className(viewClass.c_str()); // TODO: hack, fix it! - if (className == "ViewLoaderApp") className = "Page.App"; + if (className == "ViewLoaderApp") className = "Page.ViewShoppingApp"; std::replace(className.begin(), className.end(), '.', '/'); + LOGI("testtest ##### env->FindClass %" LOG_PUBLIC "s", className.c_str()); ets_class viewClassClass = env->FindClass(className.c_str()); if (!viewClassClass) { LOGI("##### Cannot find user class %" LOG_PUBLIC "s", viewClass.c_str()); diff --git a/interop/src/cpp/vmloader.cc b/interop/src/cpp/vmloader.cc index a557960ed..29b4c802f 100644 --- a/interop/src/cpp/vmloader.cc +++ b/interop/src/cpp/vmloader.cc @@ -225,6 +225,8 @@ extern "C" DLL_EXPORT KInt LoadVirtualMachine(KInt vmKind, const char* appClassP {EtsOptionType::ETS_BOOT_FILE, (char*)strdup((std::string(thisVM->sdkPath) + "/ets/etsstdlib.abc").c_str())}, #endif }; + etsVMOptions.push_back({EtsOptionType::ETS_NO_JIT, nullptr}); + etsVMOptions.push_back({EtsOptionType::ETS_LOG_LEVEL, "debug"}); for (const std::string& path : files) { etsVMOptions.push_back({EtsOptionType::ETS_BOOT_FILE, (char*)strdup(path.c_str())}); } @@ -502,6 +504,7 @@ void traverseDir(std::string root, std::vector& paths, int depth) { int rv = stat(filepath.c_str(), &statbuf); if (rv < 0) continue; if (filepath.size() >= suffix.size() && filepath.substr(filepath.size() - suffix.size()) == suffix && (statbuf.st_mode & S_IFMT) == S_IFREG) { + LOGE("testtest find %" LOG_PUBLIC "s", filepath.c_str()); paths.push_back(filepath); } if ((statbuf.st_mode & S_IFMT) == S_IFDIR) { -- Gitee From fae2fc866a6dd6dcabb8083e4693c63f52f9001e Mon Sep 17 00:00:00 2001 From: l00913061 Date: Fri, 20 Dec 2024 17:11:20 +0800 Subject: [PATCH 8/9] mediaquery Signed-off-by: l00913061 --- arkoala-arkts/arkui/src/Application.ts | 30 +++++------ arkoala-arkts/arkui/src/generated/Events.ts | 1 - .../arkui/src/generated/arkts/NativeModule.ts | 3 ++ .../arkui/src/generated/mediaquery.ts | 52 ++++++++++++++++++ .../src/generated/peers/ArkUINodeType.ts | 1 - .../peers/CallbackDeserializeCall.ts | 17 +++--- .../src/generated/peers/CallbacksChecker.ts | 1 - .../arkui/src/generated/peers/Deserializer.ts | 7 +++ arkoala/framework/native/src/SerializerBase.h | 5 ++ arkoala/framework/native/src/callbacks.cc | 4 -- .../src/generated/arkoala_api_generated.h | 8 +++ .../native/src/generated/callback_kind.h | 1 + .../src/generated/callback_managed_caller.cc | 13 ++++- .../native/src/generated/mediaquery.cc | 54 +++++++++++++++++++ 14 files changed, 165 insertions(+), 32 deletions(-) create mode 100644 arkoala-arkts/arkui/src/generated/mediaquery.ts create mode 100644 arkoala/framework/native/src/generated/mediaquery.cc diff --git a/arkoala-arkts/arkui/src/Application.ts b/arkoala-arkts/arkui/src/Application.ts index d21da5f7a..48f3d71e8 100644 --- a/arkoala-arkts/arkui/src/Application.ts +++ b/arkoala-arkts/arkui/src/Application.ts @@ -97,10 +97,10 @@ function dumpTree(node: IncrementalNode, indent: int32 = 0) { return str } - // if (indent == 0) // console.log("> Dump tree:") + if (indent == 0) console.log("> Dump tree:") let child = node.firstChild - // console.log("> " + indentToString(indent++) + "| " + node) + console.log("> " + indentToString(indent++) + "| " + node) while (child) { dumpTree(child!, indent + 1) @@ -113,7 +113,7 @@ function drawCurrentCrash(crash: Object) { let msg = crash.toString() + "\n" if (Object.hasOwn(crash, "stack")) msg += (crash as Error).stack if (!crashDumped) { - // console.log(msg) + console.log(msg) crashDumped = true } NativeModule._ShowCrash(msg ?? "unknown error message") @@ -153,18 +153,18 @@ export class Application { if (this.withLog) { UserView.stopNativeLog(1) let log = UserView.getNativeLog(1) - // if (log.length > 0) // console.log(log) + if (log.length > 0) console.log(log) } return rootPointer! } private checkEvents(what: int32) { - // console.log("ARKTS: checkEvents") + console.log("ARKTS: checkEvents") checkEvents() } private updateState() { - // console.log("ARKTS: updateState") + console.log("ARKTS: updateState") this.updateStates(this.manager!, this.root!) // Here we request to draw a frame and call custom components JS callbacks. @@ -173,7 +173,7 @@ export class Application { callScheduledCallbacks() } - withLog = false + withLog = true updateStates(manager: StateManager, root: ComputableState) { // Ensure all current state updates took effect. @@ -195,7 +195,7 @@ export class Application { try { root.value } catch (error) { - // console.log('has error in partialUpdates') + console.log('has error in partialUpdates') } // Notify subscriber. update.callback(false) @@ -209,7 +209,7 @@ export class Application { private render() { - // console.log("ARKTS: render") + console.log("ARKTS: render") } enter(arg0: int32, arg1: int32): boolean { @@ -225,7 +225,7 @@ export class Application { } catch (error) { if (error instanceof Error) { if (error.stack) { - // console.log(error.stack) + console.log(error.stack) return true } } @@ -235,14 +235,13 @@ export class Application { if (this.withLog) { UserView.stopNativeLog(1) let log = UserView.getNativeLog(1) - // if (log.length > 0) // console.log(log) + if (log.length > 0) console.log(log) } return this.exitApp } loopIteration(arg0: int32, arg1: int32) { - NativeModule._NativeLog("testtest ARKTS: loopIteration") - // step4 + console.log("ARKTS: loopIteration") this.checkEvents(arg0) this.updateState() this.render() @@ -260,7 +259,7 @@ export class Application { break } case EventType.Text.valueOf(): { - // console.log("ARKTS: [emitEvent] EventType.Text is not implemented." + type) + console.log("ARKTS: [emitEvent] EventType.Text is not implemented." + type) break } case EventType.ExitApp.valueOf(): { @@ -268,7 +267,7 @@ export class Application { break } default: { - // console.log("ARKTS: [emitEvent] type = " + type + " is unknown.") + console.log("ARKTS: [emitEvent] type = " + type + " is unknown.") break } } @@ -277,7 +276,6 @@ export class Application { } static createApplication(appUrl: string, params: string): Application { - NativeModule._NativeLog("testtest createApplication View"+appUrl) const userView = NativeModule._LoadUserView("View" + appUrl, params) if (userView == undefined) throw new Error("Cannot load user view"); return new Application(userView as UserView) diff --git a/arkoala-arkts/arkui/src/generated/Events.ts b/arkoala-arkts/arkui/src/generated/Events.ts index 025ad3e43..b8e37c8e5 100644 --- a/arkoala-arkts/arkui/src/generated/Events.ts +++ b/arkoala-arkts/arkui/src/generated/Events.ts @@ -14,7 +14,6 @@ */ export function checkEvents() { - // step5 customEventsChecker() } diff --git a/arkoala-arkts/arkui/src/generated/arkts/NativeModule.ts b/arkoala-arkts/arkui/src/generated/arkts/NativeModule.ts index b9b6f4fb7..ec1730d34 100644 --- a/arkoala-arkts/arkui/src/generated/arkts/NativeModule.ts +++ b/arkoala-arkts/arkui/src/generated/arkts/NativeModule.ts @@ -2371,4 +2371,7 @@ export class NativeModule { native static _TestGetManagedCaller(kind: int32): KPointer native static _TestGetManagedHolder(): KPointer native static _TestGetManagedReleaser(): KPointer + native static _MatchMediaSync(condition: string): boolean + native static _MediaQueryListener_onChange(thisArray: KUint8ArrayPtr, thisLength: int32): void + native static _MediaQueryListener_offChange(thisArray: KUint8ArrayPtr, thisLength: int32): void } diff --git a/arkoala-arkts/arkui/src/generated/mediaquery.ts b/arkoala-arkts/arkui/src/generated/mediaquery.ts new file mode 100644 index 000000000..c39e1f5fb --- /dev/null +++ b/arkoala-arkts/arkui/src/generated/mediaquery.ts @@ -0,0 +1,52 @@ +import { KPointer, pointer } from "@koalaui/interop" +import { RuntimeType, runtimeType } from "./peers/SerializerBase" +import { NativeModule } from "#components" +import { Serializer } from "./peers/Serializer" + +export interface MediaQueryResult { + matches: boolean + condition: string +} +export interface MediaQueryListenerInterface extends MediaQueryResult { + on(type: "change", callback: ((parameter: MediaQueryResult) => void)): void + off(type: "change", callback?: ((parameter: MediaQueryResult) => void)): void +} +export class MediaQueryListener implements MediaQueryListenerInterface { + public _matches: boolean = false + public _condition: string = "" + constructor(matches: boolean, condition: string) { + this._matches = matches + this._condition = condition + } + get matches(): boolean { + return this._matches + } + set matches(matches:boolean) { + this._matches = matches + } + get condition(): string { + return this._condition + } + set condition(condition:string) { + this._condition = condition + } + on(type: "change", callback: ((parameter: MediaQueryResult) => void)): void { + const thisSerializer: Serializer = Serializer.hold() + thisSerializer.holdAndWriteCallback(callback) + NativeModule._MediaQueryListener_onChange(thisSerializer.asArray(), thisSerializer.length()) + thisSerializer.release() + } + off(type: "change", callback?: ((parameter: MediaQueryResult) => void)): void { + const thisSerializer: Serializer = Serializer.hold() + thisSerializer.holdAndWriteCallback(callback!) + NativeModule._MediaQueryListener_offChange(thisSerializer.asArray(), thisSerializer.length()) + thisSerializer.release() + } +} +export class mediaquery { + static matchMediaSync(condition: string): MediaQueryListener { + let matches = NativeModule._MatchMediaSync(condition) + let mediaQueryListener = new MediaQueryListener(matches, condition) + return mediaQueryListener + } +} \ No newline at end of file diff --git a/arkoala-arkts/arkui/src/generated/peers/ArkUINodeType.ts b/arkoala-arkts/arkui/src/generated/peers/ArkUINodeType.ts index 9604c35fc..de59645e6 100644 --- a/arkoala-arkts/arkui/src/generated/peers/ArkUINodeType.ts +++ b/arkoala-arkts/arkui/src/generated/peers/ArkUINodeType.ts @@ -44,7 +44,6 @@ export enum ArkUINodeType { Image, ImageAnimator, ImageSpan, - IndicatorComponent, Line, LinearIndicator, List, diff --git a/arkoala-arkts/arkui/src/generated/peers/CallbackDeserializeCall.ts b/arkoala-arkts/arkui/src/generated/peers/CallbackDeserializeCall.ts index f7bbf95a6..45045b506 100644 --- a/arkoala-arkts/arkui/src/generated/peers/CallbackDeserializeCall.ts +++ b/arkoala-arkts/arkui/src/generated/peers/CallbackDeserializeCall.ts @@ -217,6 +217,7 @@ import { CustomDialogControllerOptions } from "./../ArkCustomDialogControllerInt import { IPropertySubscriber } from "./../ArkIPropertySubscriberMaterialized" import { Matrix2D } from "./../ArkMatrix2DMaterialized" import { Path2D } from "./../ArkPath2DMaterialized" +import { MediaQueryResult } from "./../mediaquery" import { NativeModule } from "#components" @@ -367,14 +368,9 @@ export function deserializeAndCallCallback_ClickEvent_SaveButtonOnClickResult_Vo _call(event, result) } export function deserializeAndCallCallback_ClickEvent_Void(thisDeserializer: Deserializer) { - // step xx - NativeModule._NativeLog("testtest deserializeAndCallCallback_ClickEvent_Void 1"); const _resourceId : int32 = thisDeserializer.readInt32() - NativeModule._NativeLog("testtest deserializeAndCallCallback_ClickEvent_Void 2 " + _resourceId); const _call = (ResourceHolder.instance().get(_resourceId) as Function1) - NativeModule._NativeLog("testtest deserializeAndCallCallback_ClickEvent_Void 3"); - let event : ClickEvent = {displayX:0, displayY:0, windowX:0, windowY:0 , screenX:0, screenY:0, x:0, y:0, target: {area: {position: {}, globalPosition: {}, width:0, height:0}}, source: SourceType.UNKNOWN, preventDefault: () => {}, timestamp:0, pressure: 0,tiltX:0, tiltY: 0, sourceTool:SourceTool.UNKNOWN} - NativeModule._NativeLog("testtest deserializeAndCallCallback_ClickEvent_Void 4 X: " + event.screenX + " Y: " + event.screenY); + let event : ClickEvent = thisDeserializer.readClickEvent() _call(event) } export function deserializeAndCallCallback_ComputedBarAttribute_Void(thisDeserializer: Deserializer) { @@ -2028,10 +2024,14 @@ export function deserializeAndCallWithThemeInterface(thisDeserializer: Deseriali let _continuation : Function1 = thisDeserializer.readCallback_WithThemeAttribute_Void() _continuation(_call(options)) } +export function deserializeAndCallCallback_MediaQuery(thisDeserializer: Deserializer) { + const _resourceId : int32 = thisDeserializer.readInt32() + const _call = (ResourceHolder.instance().get(_resourceId) as Function1) + let result : MediaQueryResult = thisDeserializer.readMediaQueryResult(); + _call(result) +} export function deserializeAndCallCallback(thisDeserializer: Deserializer) { const kind : int32 = thisDeserializer.readInt32() - // step6 kind - NativeModule._NativeLog("testtest deserializeAndCallCallback " + kind); switch (kind) { case 0/*CallbackKind.Kind_AccessibilityCallback*/: return deserializeAndCallAccessibilityCallback(thisDeserializer); case 1/*CallbackKind.Kind_ButtonTriggerClickCallback*/: return deserializeAndCallButtonTriggerClickCallback(thisDeserializer); @@ -2267,6 +2267,7 @@ export function deserializeAndCallCallback(thisDeserializer: Deserializer) { case 231/*CallbackKind.Kind_VoidCallback*/: return deserializeAndCallVoidCallback(thisDeserializer); case 232/*CallbackKind.Kind_WebKeyboardCallback*/: return deserializeAndCallWebKeyboardCallback(thisDeserializer); case 233/*CallbackKind.Kind_WithThemeInterface*/: return deserializeAndCallWithThemeInterface(thisDeserializer); + case 234/*CallbackKind.Kind_Callback_MeidaQuery*/: return deserializeAndCallCallback_MediaQuery(thisDeserializer); } throw new Error("Unknown callback kind") } \ No newline at end of file diff --git a/arkoala-arkts/arkui/src/generated/peers/CallbacksChecker.ts b/arkoala-arkts/arkui/src/generated/peers/CallbacksChecker.ts index 70cf29149..861a5eefc 100644 --- a/arkoala-arkts/arkui/src/generated/peers/CallbacksChecker.ts +++ b/arkoala-arkts/arkui/src/generated/peers/CallbacksChecker.ts @@ -15,7 +15,6 @@ const buffer = new KBuffer(bufferSize) const deserializer = new Deserializer(buffer.buffer, bufferSize) export function checkArkoalaCallbacks() { while (true) { - // step6 deserializer.resetCurrentPosition() let result = nativeModule()._CheckArkoalaCallbackEvent(buffer.buffer, bufferSize) if (result == 0) break diff --git a/arkoala-arkts/arkui/src/generated/peers/Deserializer.ts b/arkoala-arkts/arkui/src/generated/peers/Deserializer.ts index d0b88f036..7991c5542 100644 --- a/arkoala-arkts/arkui/src/generated/peers/Deserializer.ts +++ b/arkoala-arkts/arkui/src/generated/peers/Deserializer.ts @@ -250,6 +250,7 @@ import { TextPickerDialogInternal } from "./../ArkTextPickerDialogMaterialized" import { TimePickerDialogInternal } from "./../ArkTimePickerDialogMaterialized" import { WebCookieInternal } from "./../ArkWebCookieMaterialized" import { MutableStyledStringInternal } from "./../ArkMutableStyledStringMaterialized" +import { MediaQueryResult } from "./../mediaquery" export class Deserializer extends DeserializerBase { constructor(data: KUint8ArrayPtr, length: int32) { @@ -19250,4 +19251,10 @@ export class Deserializer extends DeserializerBase { const _call : KPointer = this.readPointer() return (error?: Array | undefined): void => { const _argsSerializer : Serializer = Serializer.hold(); _argsSerializer.writeInt32(_resource.resourceId); _argsSerializer.writePointer(_call); let error_type : int32 = RuntimeType.UNDEFINED; error_type = runtimeType(error); _argsSerializer.writeInt8(error_type as int32); if ((RuntimeType.UNDEFINED) != (error_type)) {; const error_value = error!; _argsSerializer.writeInt32(error_value.length as int32); for (let i = 0; i < error_value.length; i++) {; const error_value_element = error_value[i]; _argsSerializer.writeString(error_value_element); } } NativeModule._CallCallback(CallbackKind.Kind_Callback_Opt_Array_String_Void.ordinal, _argsSerializer.asArray(), _argsSerializer.length()); _argsSerializer.release(); return; } } + readMediaQueryResult(): MediaQueryResult { + let valueDeserializer : Deserializer = this + const matches : boolean = valueDeserializer.readBoolean() + const condition : string = (valueDeserializer.readString() as string) + return {matches: matches, condition: condition} + } } diff --git a/arkoala/framework/native/src/SerializerBase.h b/arkoala/framework/native/src/SerializerBase.h index ab9bd8fcc..a5ebbca17 100644 --- a/arkoala/framework/native/src/SerializerBase.h +++ b/arkoala/framework/native/src/SerializerBase.h @@ -190,6 +190,11 @@ public: writeInt64((Ark_Int64)buffer.data); writeInt64(buffer.length); } + + void writeMediaQueryResult(Ark_MediaQueryResult result) { + writeBoolean(result.matches); + writeString(result.media); + } }; #endif // _SERIALIZER_BASE_H \ No newline at end of file diff --git a/arkoala/framework/native/src/callbacks.cc b/arkoala/framework/native/src/callbacks.cc index e1f8d6c60..69352af20 100644 --- a/arkoala/framework/native/src/callbacks.cc +++ b/arkoala/framework/native/src/callbacks.cc @@ -19,8 +19,6 @@ #include "common-interop.h" #include "Serializers.h" -#include "interop-logging.h" - enum CallbackEventKind { Event_CallCallback = 0, Event_HoldManagedResource = 1, @@ -84,8 +82,6 @@ void impl_HoldArkoalaResource(Ark_Int32 resourceId) { KOALA_INTEROP_V1(HoldArkoalaResource, KInt) void enqueueArkoalaCallback(const CallbackBuffer* event) { - // step3 - LOGE0("testtest enqueueArkoalaCallback"); callbackEventsQueue.push_back(Event_CallCallback); callbackCallSubqueue.push_back(*event); } diff --git a/arkoala/framework/native/src/generated/arkoala_api_generated.h b/arkoala/framework/native/src/generated/arkoala_api_generated.h index 38f177cab..25b9e2d76 100644 --- a/arkoala/framework/native/src/generated/arkoala_api_generated.h +++ b/arkoala/framework/native/src/generated/arkoala_api_generated.h @@ -20740,7 +20740,15 @@ typedef struct GENERATED_ArkUIAnyAPI { Ark_Int32 version; } GENERATED_ArkUIAnyAPI; +typedef struct Ark_MediaQueryResult{ + Ark_Boolean matches; + Ark_String media; +}Ark_MediaQueryResult; +typedef struct Callback_MediaQuery_Void { + Ark_CallbackResource resource; + void (*call)(const Ark_Int32 resourceId, const Ark_MediaQueryResult result); +} Callback_MediaQuery_Void; struct Ark_AnyAPI { diff --git a/arkoala/framework/native/src/generated/callback_kind.h b/arkoala/framework/native/src/generated/callback_kind.h index 3ef343f51..38d2fb7c5 100644 --- a/arkoala/framework/native/src/generated/callback_kind.h +++ b/arkoala/framework/native/src/generated/callback_kind.h @@ -237,6 +237,7 @@ typedef enum CallbackKind { Kind_VoidCallback = 231, Kind_WebKeyboardCallback = 232, Kind_WithThemeInterface = 233, + Kind_Callback_MeidaQuery = 234, } CallbackKind; #endif diff --git a/arkoala/framework/native/src/generated/callback_managed_caller.cc b/arkoala/framework/native/src/generated/callback_managed_caller.cc index 6764d478c..05c004124 100644 --- a/arkoala/framework/native/src/generated/callback_managed_caller.cc +++ b/arkoala/framework/native/src/generated/callback_managed_caller.cc @@ -258,7 +258,6 @@ void callManagedCallback_ClickEvent_SaveButtonOnClickResult_Void(Ark_Int32 resou } void callManagedCallback_ClickEvent_Void(Ark_Int32 resourceId, Ark_ClickEvent event) { - // step2 CallbackBuffer __buffer = {{}, {}}; const Ark_CallbackResource __callbackResource = {resourceId, holdManagedCallbackResource, releaseManagedCallbackResource}; __buffer.resourceHolder.holdCallbackResource(&__callbackResource); @@ -3053,6 +3052,17 @@ void callManagedWithThemeInterface(Ark_Int32 resourceId, Ark_WithThemeOptions op argsSerializer.writePointer(reinterpret_cast(continuation.call)); enqueueArkoalaCallback(&__buffer); } +void callManagedMeidaQuery(Ark_Int32 resourceId, Ark_MediaQueryResult result) +{ + CallbackBuffer __buffer = {{}, {}}; + const Ark_CallbackResource __callbackResource = {resourceId, holdManagedCallbackResource, releaseManagedCallbackResource}; + __buffer.resourceHolder.holdCallbackResource(&__callbackResource); + Serializer argsSerializer = Serializer(__buffer.buffer, &(__buffer.resourceHolder)); + argsSerializer.writeInt32(Kind_Callback_ClickEvent_Void); + argsSerializer.writeInt32(resourceId); + argsSerializer.writeMediaQueryResult(result); + enqueueArkoalaCallback(&__buffer); +} void* getManagedCallbackCaller(CallbackKind kind) { switch (kind) { @@ -3290,6 +3300,7 @@ void* getManagedCallbackCaller(CallbackKind kind) case Kind_VoidCallback: return reinterpret_cast(callManagedVoidCallback); case Kind_WebKeyboardCallback: return reinterpret_cast(callManagedWebKeyboardCallback); case Kind_WithThemeInterface: return reinterpret_cast(callManagedWithThemeInterface); + case Kind_Callback_MeidaQuery: return reinterpret_cast(callManagedMeidaQuery); } return nullptr; } \ No newline at end of file diff --git a/arkoala/framework/native/src/generated/mediaquery.cc b/arkoala/framework/native/src/generated/mediaquery.cc new file mode 100644 index 000000000..a147de6b8 --- /dev/null +++ b/arkoala/framework/native/src/generated/mediaquery.cc @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "mediaquery.h" + +#include "common-interop.h" +#include "SerializerBase.h" +#include "DeserializerBase.h" +#include + + + + +Ark_Boolean impl_MatchMediaSync(Ark_String condition) { + return GetAnyImpl(static_cast((GENERATED_Ark_APIVariantKind::GENERATED_MQ), + GENERATED_ARKUI_MQ_API_VERSION, nullptr))->MatchMediaSync(condition); +} +KOALA_INTEROP_V1(MatchMediaSync, string) + + +void impl_MediaQueryListener_onChange(uint8_t* thisArray, int32_t thisLength) { + Ark_NodeHandle self = reinterpret_cast(thisPtr); + Deserializer thisDeserializer(thisArray, thisLength); + Callback_MediaQuery_Void value_value = {thisDeserializer.readCallbackResource(), + reinterpret_cast + (thisDeserializer.readPointerOrDefault(reinterpret_cast(getManagedCallbackCaller(Kind_Callback_MeidaQuery))))};; + GetAnyImpl(static_cast((GENERATED_Ark_APIVariantKind::GENERATED_MQ), + GENERATED_ARKUI_MQ_API_VERSION, nullptr))->OnChange((const Callback_MediaQuery_Void*)&value_value); +} +KOALA_INTEROP_V2(MediaQueryListener_onChange, uint8_t*, int32_t) + +void impl_MediaQueryListener_offChange(uint8_t* thisArray, int32_t thisLength) { + Ark_NodeHandle self = reinterpret_cast(thisPtr); + Deserializer thisDeserializer(thisArray, thisLength); + Callback_MediaQuery_Void value_value = {thisDeserializer.readCallbackResource(), + reinterpret_cast + (thisDeserializer.readPointerOrDefault(reinterpret_cast(getManagedCallbackCaller(Kind_Callback_MeidaQuery))))};; + GetAnyImpl(static_cast((GENERATED_Ark_APIVariantKind::GENERATED_MQ), + GENERATED_ARKUI_MQ_API_VERSION, nullptr))->OffChange((const Callback_MediaQuery_Void*)&value_value); +} +KOALA_INTEROP_V2(MediaQueryListener_offChange, uint8_t*, int32_t) + -- Gitee From a5c06209c9aa0b1cd5902c2df7b941d9e2583461 Mon Sep 17 00:00:00 2001 From: lishihao Date: Thu, 9 Jan 2025 06:32:50 +0000 Subject: [PATCH 9/9] update arkoala/framework/native/src/generated/mediaquery.cc. Signed-off-by: lishihao --- arkoala/framework/native/src/generated/mediaquery.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arkoala/framework/native/src/generated/mediaquery.cc b/arkoala/framework/native/src/generated/mediaquery.cc index a147de6b8..b03eb67b3 100644 --- a/arkoala/framework/native/src/generated/mediaquery.cc +++ b/arkoala/framework/native/src/generated/mediaquery.cc @@ -27,7 +27,7 @@ Ark_Boolean impl_MatchMediaSync(Ark_String condition) { return GetAnyImpl(static_cast((GENERATED_Ark_APIVariantKind::GENERATED_MQ), GENERATED_ARKUI_MQ_API_VERSION, nullptr))->MatchMediaSync(condition); } -KOALA_INTEROP_V1(MatchMediaSync, string) +KOALA_INTEROP_V1(MatchMediaSync, Ark_Boolean, string) void impl_MediaQueryListener_onChange(uint8_t* thisArray, int32_t thisLength) { -- Gitee