diff --git a/examples/jsMultiContext/.gitignore b/examples/jsMultiContext/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/examples/jsMultiContext/.gitignore @@ -0,0 +1,12 @@ +/node_modules +/oh_modules +/local.properties +/.idea +**/build +/.hvigor +.cxx +/.clangd +/.clang-format +/.clang-tidy +**/.test +/.appanalyzer \ No newline at end of file diff --git a/examples/jsMultiContext/AppScope/app.json5 b/examples/jsMultiContext/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c5e8fbd7b9c82e3580e794b44c4313c41601bb54 --- /dev/null +++ b/examples/jsMultiContext/AppScope/app.json5 @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2025 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. + */ +{ + "app": { + "bundleName": "com.example.jscontext", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:layered_image", + "label": "$string:app_name" + } +} diff --git a/examples/jsMultiContext/AppScope/resources/base/element/string.json b/examples/jsMultiContext/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..3ff48a288d3ce0181a48484ca1f066d499c22dfc --- /dev/null +++ b/examples/jsMultiContext/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "jscontext" + } + ] +} diff --git a/examples/jsMultiContext/AppScope/resources/base/media/background.png b/examples/jsMultiContext/AppScope/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/examples/jsMultiContext/AppScope/resources/base/media/background.png differ diff --git a/examples/jsMultiContext/AppScope/resources/base/media/foreground.png b/examples/jsMultiContext/AppScope/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..eb9427585b36d14b12477435b6419d1f07b3e0bb Binary files /dev/null and b/examples/jsMultiContext/AppScope/resources/base/media/foreground.png differ diff --git a/examples/jsMultiContext/AppScope/resources/base/media/layered_image.json b/examples/jsMultiContext/AppScope/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/examples/jsMultiContext/AppScope/resources/base/media/layered_image.json @@ -0,0 +1,7 @@ +{ + "layered-image": + { + "background" : "$media:background", + "foreground" : "$media:foreground" + } +} \ No newline at end of file diff --git a/examples/jsMultiContext/build-profile.json5 b/examples/jsMultiContext/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..05055d1a2dd6ffeef8c2a2af868aa0221458e4b6 --- /dev/null +++ b/examples/jsMultiContext/build-profile.json5 @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2025 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. + */ + { + "app": { + "signingConfigs": [], + "products": [ + { + "name": "default", + "signingConfig": "default", + "compileSdkVersion": 20, + "compatibleSdkVersion": 20, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "car", + "srcPath": "./car", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/examples/jsMultiContext/code-linter.json5 b/examples/jsMultiContext/code-linter.json5 new file mode 100644 index 0000000000000000000000000000000000000000..5c4682f8164874ec7e9cb8f99ff8b3228ffbc126 --- /dev/null +++ b/examples/jsMultiContext/code-linter.json5 @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2025 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. + */ +{ + "files": [ + "**/*.ets" + ], + "ignore": [ + "**/src/ohosTest/**/*", + "**/src/test/**/*", + "**/src/mock/**/*", + "**/node_modules/**/*", + "**/oh_modules/**/*", + "**/build/**/*", + "**/.preview/**/*" + ], + "ruleSet": [ + "plugin:@performance/recommended", + "plugin:@typescript-eslint/recommended" + ], + "rules": { + "@security/no-unsafe-aes": "error", + "@security/no-unsafe-hash": "error", + "@security/no-unsafe-mac": "warn", + "@security/no-unsafe-dh": "error", + "@security/no-unsafe-dsa": "error", + "@security/no-unsafe-ecdsa": "error", + "@security/no-unsafe-rsa-encrypt": "error", + "@security/no-unsafe-rsa-sign": "error", + "@security/no-unsafe-rsa-key": "error", + "@security/no-unsafe-dsa-key": "error", + "@security/no-unsafe-dh-key": "error", + "@security/no-unsafe-3des": "error" + } +} \ No newline at end of file diff --git a/examples/jsMultiContext/entry/.gitignore b/examples/jsMultiContext/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/examples/jsMultiContext/entry/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/examples/jsMultiContext/entry/build-profile.json5 b/examples/jsMultiContext/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..1f28520fc48e32a1440b8c3ed958205edb0f123e --- /dev/null +++ b/examples/jsMultiContext/entry/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 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. + */ +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + "abiFilters": ["armeabi-v7a","arm64-v8a","x86_64"] + } + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + }, + "nativeLib": { + "debugSymbol": { + "strip": true, + "exclude": [] + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/examples/jsMultiContext/entry/hvigorfile.ts b/examples/jsMultiContext/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..f8b117a17af3b2d7cb87a7680e29e2bb8ccd5b46 --- /dev/null +++ b/examples/jsMultiContext/entry/hvigorfile.ts @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 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. + */ +import { hapTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: hapTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins: [] /* Custom plugin to extend the functionality of Hvigor. */ +} \ No newline at end of file diff --git a/examples/jsMultiContext/entry/obfuscation-rules.txt b/examples/jsMultiContext/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/examples/jsMultiContext/entry/obfuscation-rules.txt @@ -0,0 +1,23 @@ +# Define project specific obfuscation rules here. +# You can include the obfuscation configuration files in the current module's build-profile.json5. +# +# For more details, see +# https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/source-obfuscation-V5 + +# Obfuscation options: +# -disable-obfuscation: disable all obfuscations +# -enable-property-obfuscation: obfuscate the property names +# -enable-toplevel-obfuscation: obfuscate the names in the global scope +# -compact: remove unnecessary blank spaces and all line feeds +# -remove-log: remove all console.* statements +# -print-namecache: print the name cache that contains the mapping from the old names to new names +# -apply-namecache: reuse the given cache file + +# Keep options: +# -keep-property-name: specifies property names that you want to keep +# -keep-global-name: specifies names that you want to keep in the global scope + +-enable-property-obfuscation +-enable-toplevel-obfuscation +-enable-filename-obfuscation +-enable-export-obfuscation \ No newline at end of file diff --git a/examples/jsMultiContext/entry/oh-package-lock.json5 b/examples/jsMultiContext/entry/oh-package-lock.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e76a9588d75c64a099d8baa57b0077db3020b546 --- /dev/null +++ b/examples/jsMultiContext/entry/oh-package-lock.json5 @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2025 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. + */ +{ + "meta": { + "stableOrder": true + }, + "lockfileVersion": 3, + "ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.", + "specifiers": { + "car@../car": "car@../car", + "libentry.so@src/main/cpp/types/libentry": "libentry.so@src/main/cpp/types/libentry" + }, + "packages": { + "car@../car": { + "name": "car", + "version": "1.0.0", + "resolved": "../car", + "registryType": "local", + "packageType": "InterfaceHar" + }, + "libentry.so@src/main/cpp/types/libentry": { + "name": "libentry.so", + "version": "1.0.0", + "resolved": "src/main/cpp/types/libentry", + "registryType": "local" + } + } +} \ No newline at end of file diff --git a/examples/jsMultiContext/entry/oh-package.json5 b/examples/jsMultiContext/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..59a54466473016b7f1bdff145b32aa827558a473 --- /dev/null +++ b/examples/jsMultiContext/entry/oh-package.json5 @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2025 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. + */ +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libentry.so": "file:./src/main/cpp/types/libentry", + "car": "file:../car" + } +} \ No newline at end of file diff --git a/examples/jsMultiContext/entry/src/main/cpp/napi_init.cpp b/examples/jsMultiContext/entry/src/main/cpp/napi_init.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3d02b6561c78705829e8f6f8dfa295888f8c07ee --- /dev/null +++ b/examples/jsMultiContext/entry/src/main/cpp/napi_init.cpp @@ -0,0 +1,389 @@ +/* + * Copyright (c) 2025 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 "hilog/log.h" +#include "napi/native_api.h" +#include +#include +#include + +extern "C" napi_status napi_create_ark_context(napi_env env, napi_env *newEnv); +extern "C" napi_status napi_switch_ark_context(napi_env env); +extern "C" napi_status napi_destroy_ark_context(napi_env env); + +static std::map envMaps_; + +const int ATTR_INDEX_0 = 0; +const int ATTR_INDEX_1 = 1; +const int ATTR_INDEX_2 = 2; +const int ATTR_INDEX_3 = 3; +const int ATTR_INDEX_4 = 4; +const int BUFFER_SIZE = 4096; + +std::string GetString(const napi_env &env, const napi_value &value) +{ + std::unique_ptr buffer = std::make_unique(BUFFER_SIZE); + size_t length = 0; + napi_get_value_string_utf8(env, value, buffer.get(), BUFFER_SIZE, &length); + return std::string(buffer.get(), length); +} + + +// Helper functions for NAPI_Global_callFunctionInContext1 +static napi_value LoadAndGetProperty(napi_env env, const char* path, const char* propertyName) +{ + napi_value plugin = nullptr; + napi_status status = napi_load_module_with_info(env, path, "com.example.jscontext/entry", &plugin); + if (status != napi_ok) { + OH_LOG_INFO(LOG_APP, "[jsMultiContext] load module info of env failed"); + return nullptr; + } + + napi_value property = nullptr; + status = napi_get_named_property(env, plugin, propertyName, &property); + if (status != napi_ok) { + OH_LOG_INFO(LOG_APP, "[jsMultiContext] get name property of env failed"); + return nullptr; + } + return property; +} + +static void CallFunctionAndLogResult(napi_env env, napi_value func, napi_value arg, const char* logPrefix) +{ + napi_value result = nullptr; + napi_value args[1] = {arg}; + napi_status status = napi_call_function(env, nullptr, func, 1, args, &result); + if (status != napi_ok) { + OH_LOG_INFO(LOG_APP, "[jsMultiContext] call function of env failed"); + return; + } + + int32_t ret = 0; + status = napi_get_value_int32(env, result, &ret); + if (status != napi_ok) { + OH_LOG_INFO(LOG_APP, "[jsMultiContext] napi_get_value_int32 of env failed"); + } else { + OH_LOG_INFO(LOG_APP, "[jsMultiContext] %s ret is %{public}d", logPrefix, ret); + } +} + +// context1 +static napi_value NAPI_Global_callFunctionInContext1(napi_env env, napi_callback_info info) +{ + OH_LOG_INFO(LOG_APP, "[jsMultiContext] NAPI_Global_callFunctionInContext1 called"); + napi_status status = napi_ok; + + size_t argc = 1; + napi_value args[ATTR_INDEX_1] = {nullptr}; + if (napi_get_cb_info(env, info, &argc, args, nullptr, nullptr) != napi_ok) { + return nullptr; + } + + napi_value getLocation1 = LoadAndGetProperty(env, "entry/src/main/ets/pages/plugin1", "GetLocation"); + napi_value getLocation2 = LoadAndGetProperty(env, "entry/src/main/ets/pages/plugin2", "GetLocation"); + + if (getLocation1 != nullptr) { + CallFunctionAndLogResult(env, args[ATTR_INDEX_0], getLocation1, "plugin1"); + } + if (getLocation2 != nullptr) { + CallFunctionAndLogResult(env, args[ATTR_INDEX_0], getLocation2, "plugin2"); + } + + OH_LOG_INFO(LOG_APP, "[jsMultiContext] NAPI_Global_callFunctionInContext1 finished"); + return nullptr; +} + +// Helper functions for NAPI_Global_callFunctionInContext2 +static napi_env CreateAndSwitchContext(napi_env env) +{ + napi_env newEnv = nullptr; + napi_status status = napi_create_ark_context(env, &newEnv); + if (status != napi_ok) { + OH_LOG_INFO(LOG_APP, "[jsMultiContext] create ark context failed"); + return nullptr; + } + napi_switch_ark_context(newEnv); + return newEnv; +} + +// context2 +static napi_value NAPI_Global_callFunctionInContext2(napi_env env, napi_callback_info info) +{ + OH_LOG_INFO(LOG_APP, "[jsMultiContext] NAPI_Global_callFunctionInContext2 called"); + + size_t argc = 1; + napi_value args[ATTR_INDEX_1] = {nullptr}; + if (napi_get_cb_info(env, info, &argc, args, nullptr, nullptr) != napi_ok) { + return nullptr; + } + + napi_value getLocation1 = LoadAndGetProperty(env, "entry/src/main/ets/pages/plugin1", "GetLocation"); + napi_env newEnv2 = CreateAndSwitchContext(env); + if (newEnv2 == nullptr) { + return nullptr; + } + + napi_value getLocation2 = LoadAndGetProperty(newEnv2, "entry/src/main/ets/pages/plugin2", "GetLocation"); + if (getLocation2 != nullptr) { + CallFunctionAndLogResult(newEnv2, args[ATTR_INDEX_0], getLocation2, "plugin2 in new context"); + } + + napi_switch_ark_context(env); + if (getLocation1 != nullptr) { + CallFunctionAndLogResult(env, args[ATTR_INDEX_0], getLocation1, "plugin1 in original context"); + } + + OH_LOG_INFO(LOG_APP, "[jsMultiContext] NAPI_Global_callFunctionInContext2 finished"); + napi_destroy_ark_context(newEnv2); + return nullptr; +} + +// Helper functions for NAPI_Global_RequirePlugin +static napi_value SetupPluginEnv(napi_env env, napi_env pluginEnv, napi_value hmsValue) +{ + napi_status status = napi_switch_ark_context(pluginEnv); + if (status != napi_ok) { + OH_LOG_INFO(LOG_APP, "[jsMultiContext] switch context status failed. %{public}d", status); + return nullptr; + } + + napi_value plugin_global; + status = napi_get_global(pluginEnv, &plugin_global); + if (status != napi_ok) { + OH_LOG_INFO(LOG_APP, "[jsMultiContext] napi_get_global failed. %{public}d", status); + return nullptr; + } + + status = napi_set_named_property(pluginEnv, plugin_global, "hms", hmsValue); + if (status != napi_ok) { + OH_LOG_INFO(LOG_APP, "[jsMultiContext] napi_set_named_property failed. %{public}d", status); + } + return plugin_global; +} + +static napi_value NAPI_Global_RequirePlugin(napi_env env, napi_callback_info info) +{ + size_t argc = 2; + napi_value args[ATTR_INDEX_2]; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + std::string id = GetString(env, args[ATTR_INDEX_0]); + OH_LOG_INFO(LOG_APP, "[jsMultiContext] native require plugin id is %{public}s", id.c_str()); + + napi_env pluginEnv = nullptr; + napi_status status = napi_create_ark_context(env, &pluginEnv); + if (status != napi_ok) { + OH_LOG_INFO(LOG_APP, "[jsMultiContext] create ark context failed. %{public}d", status); + return nullptr; + } + + SetupPluginEnv(env, pluginEnv, args[ATTR_INDEX_1]); + + napi_value pluginObj = nullptr; + status = napi_load_module_with_info(pluginEnv, id.c_str(), "com.example.jscontext/entry", &pluginObj); + if (status != napi_ok) { + OH_LOG_INFO(LOG_APP, "[jsMultiContext] native napi_load_module_with_info failed"); + } + + napi_value car = nullptr; + status = napi_get_named_property(pluginEnv, pluginObj, "car", &car); + if (status != napi_ok) { + OH_LOG_INFO(LOG_APP, "[jsMultiContext] get car failed"); + } + + napi_switch_ark_context(env); + return car; +} + +// Helper functions for NAPI_Global_nativeRequirePluginComponent +static bool InitializeArkUIEnv(napi_env env) +{ + auto ret = OH_ArkUI_InitModuleForArkTSEnv(env); + if (ret != ARKUI_ERROR_CODE_NO_ERROR) { + OH_LOG_INFO(LOG_APP, "[jsMultiContext] OH_ArkUI_InitModuleForArkTSEnv failed"); + return false; + } + return true; +} + +static napi_value NAPI_Global_nativeRequirePluginComponent(napi_env env, napi_callback_info info) +{ + size_t argc = 3; + napi_value args[ATTR_INDEX_3] = {}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + OH_LOG_INFO(LOG_APP, "[jsMultiContext] id = %{public}s", GetString(env, args[ATTR_INDEX_0]).c_str()); + + ArkUI_NodeContentHandle nodeHandle = nullptr; + int32_t code = OH_ArkUI_GetNodeContentFromNapiValue(env, args[ATTR_INDEX_1], &nodeHandle); + if (code != ARKUI_ERROR_CODE_NO_ERROR) { + OH_LOG_INFO(LOG_APP, "[jsMultiContext] getNodeContent failed"); + } + + napi_env newEnv2 = nullptr; + napi_status status = napi_create_ark_context(env, &newEnv2); + if (status != napi_ok) { + OH_LOG_INFO(LOG_APP, "[jsMultiContext] create ark context failed"); + } + + OH_LOG_INFO(LOG_APP, "[jsMultiContext] create NAPI_Global_nativeRequirePluginComponent p = %{public}p", newEnv2); + envMaps_["envArkui"] = newEnv2; + + status = napi_switch_ark_context(newEnv2); + if (status != napi_ok) { + OH_LOG_INFO(LOG_APP, "[jsMultiContext] switch component context failed"); + } + + InitializeArkUIEnv(newEnv2); + + std::string car = "car"; + napi_value pluginObj; + napi_status status1 = napi_load_module_with_info(newEnv2, car.c_str(), "com.example.jscontext/entry", &pluginObj); + if (status1 != napi_ok) { + OH_LOG_INFO(LOG_APP, "[jsMultiContext] napi_load_module_with_info failed"); + } + + napi_value carComponent = nullptr; + status = napi_get_named_property(newEnv2, pluginObj, "InitBuilder", &carComponent); + if (status != napi_ok) { + OH_LOG_INFO(LOG_APP, "[jsMultiContext] native fetch carContent failed"); + } + + napi_value result2 = nullptr; + status = napi_call_function(newEnv2, pluginObj, carComponent, 1, &args[ATTR_INDEX_2], &result2); + if (status != napi_ok) { + OH_LOG_INFO(LOG_APP, "[jsMultiContext] napi_call_function failed"); + } + + napi_switch_ark_context(env); + return result2; +} + +static napi_value NAPI_Global_nativeDestroyPluginComponent(napi_env env, napi_callback_info info) +{ + size_t argc = 1; + napi_value args[ATTR_INDEX_1] = {}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + auto pluginName = GetString(env, args[ATTR_INDEX_0]); + OH_LOG_INFO(LOG_APP, "[jsMultiContext] DestroyPlugin %{public}s", pluginName.c_str()); + + if (envMaps_.find(pluginName) != envMaps_.end()) { + OH_LOG_INFO(LOG_APP, "[jsMultiContext] DestroyPlugin success! p = %{public}p", envMaps_[pluginName]); + + OH_ArkUI_NotifyArkTSEnvDestroy(envMaps_[pluginName]); + auto ret = napi_destroy_ark_context(envMaps_[pluginName]); + if (ret != napi_ok) { + OH_LOG_INFO(LOG_APP, "[jsMultiContext] DestroyPlugin failed!"); + return nullptr; + } + envMaps_.erase(pluginName); + } + return nullptr; +} + +// Helper functions for NAPI_Global_nativeRequirePlugins +static bool SetupPluginEnvironment(napi_env env, const std::string& pluginName) +{ + if (envMaps_.find(pluginName) != envMaps_.end()) { + return true; + } + + napi_env newEnv = nullptr; + napi_status status = napi_create_ark_context(env, &newEnv); + if (status != napi_ok) { + OH_LOG_INFO(LOG_APP, "[jsMultiContext] create ark context of %{public}s failed", pluginName.c_str()); + return false; + } + + envMaps_[pluginName] = newEnv; + OH_LOG_INFO(LOG_APP, "[jsMultiContext] create envMaps_[%{public}s] p = %{public}p", pluginName.c_str(), newEnv); + + status = napi_switch_ark_context(newEnv); + if (status != napi_ok) { + OH_LOG_INFO(LOG_APP, "[jsMultiContext] switch %{public}s failed", pluginName.c_str()); + return false; + } + + if (!InitializeArkUIEnv(newEnv)) { + return false; + } + + return true; +} + +static napi_value NAPI_Global_nativeRequirePlugins(napi_env env, napi_callback_info info) +{ + size_t argc = 4; + napi_value args[ATTR_INDEX_4] = {}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + auto moduleName = GetString(env, args[ATTR_INDEX_0]); + auto builderFunc = GetString(env, args[ATTR_INDEX_1]); + auto pluginName = GetString(env, args[ATTR_INDEX_3]); + if (!SetupPluginEnvironment(env, pluginName)) { + return nullptr; + } + + napi_value pluginObj; + napi_status status = napi_load_module_with_info( + envMaps_[pluginName], moduleName.c_str(), "com.example.jscontext/entry", &pluginObj); + if (status != napi_ok) { + OH_LOG_INFO(LOG_APP, "[jsMultiContext] load module %{public}s failed", moduleName.c_str()); + } + + napi_value component = nullptr; + status = napi_get_named_property(envMaps_[pluginName], pluginObj, builderFunc.c_str(), &component); + if (status != napi_ok) { + OH_LOG_INFO(LOG_APP, "[jsMultiContext] fetch %{public}s failed", builderFunc.c_str()); + } + + napi_value result = nullptr; + napi_value para[1] = {args[ATTR_INDEX_2]}; + status = napi_call_function(envMaps_[pluginName], pluginObj, component, 1, para, &result); + if (status != napi_ok) { + OH_LOG_INFO(LOG_APP, "[jsMultiContext] call %{public}s failed", builderFunc.c_str()); + } + + napi_switch_ark_context(env); + return result; +} + +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + napi_property_descriptor desc[] = { + {"callFunctionInContext1", nullptr, NAPI_Global_callFunctionInContext1, nullptr, nullptr, nullptr, napi_default, + nullptr}, + {"callFunctionInContext2", nullptr, NAPI_Global_callFunctionInContext2, nullptr, nullptr, nullptr, napi_default, + nullptr}, + {"nativeRequirePlugin", nullptr, NAPI_Global_RequirePlugin, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"nativeRequirePluginComponent", nullptr, NAPI_Global_nativeRequirePluginComponent, nullptr, nullptr, nullptr, + napi_default, nullptr}, + {"nativeDestroyPluginComponent", nullptr, NAPI_Global_nativeDestroyPluginComponent, nullptr, nullptr, nullptr, + napi_default, nullptr}, + {"nativeRequirePlugins", nullptr, NAPI_Global_nativeRequirePlugins, nullptr, nullptr, nullptr, napi_default, + nullptr}}; + napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[ATTR_INDEX_0]), desc); + return exports; +} +EXTERN_C_END + +static napi_module demoModule = { + .nm_version = 1, + .nm_flags = 0, + .nm_filename = nullptr, + .nm_register_func = Init, + .nm_modname = "entry", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } \ No newline at end of file diff --git a/examples/jsMultiContext/entry/src/main/cpp/types/libentry/Index.d.ts b/examples/jsMultiContext/entry/src/main/cpp/types/libentry/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..4e22ac174f17fa712a889c84bb911a402481a31f --- /dev/null +++ b/examples/jsMultiContext/entry/src/main/cpp/types/libentry/Index.d.ts @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2025 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. + */ +export const callFunctionInContext1: (func: (func: () => number) => {}) => number; + +export const callFunctionInContext2: (func: (func: () => number) => {}) => number; + +export const nativeRequirePlugin: (id, hms) => object; + +export const nativeRequirePluginComponent: (id, object, context) => object; + +export const nativeDestroyPluginComponent: (pluginName)=>{}; + +export const nativeRequirePlugins: (moduleName, builderFunc, context, pluginName) => object; \ No newline at end of file diff --git a/examples/jsMultiContext/entry/src/main/cpp/types/libentry/oh-package.json5 b/examples/jsMultiContext/entry/src/main/cpp/types/libentry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c69ca2198f11d3288b2ac61227a583604b647c78 --- /dev/null +++ b/examples/jsMultiContext/entry/src/main/cpp/types/libentry/oh-package.json5 @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 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. + */ +{ + "name": "libentry.so", + "types": "./Index.d.ts", + "version": "1.0.0", + "description": "Please describe the basic information." +} \ No newline at end of file diff --git a/examples/jsMultiContext/entry/src/main/ets/entryability/EntryAbility.ets b/examples/jsMultiContext/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..b12b706076bc833e0f1c073e99881ef3b3a84004 --- /dev/null +++ b/examples/jsMultiContext/entry/src/main/ets/entryability/EntryAbility.ets @@ -0,0 +1,44 @@ +import { AbilityConstant, ConfigurationConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; + +const DOMAIN = 0x0000; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy(): void { + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err) => { + if (err.code) { + hilog.error(DOMAIN, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err)); + return; + } + hilog.info(DOMAIN, 'testTag', 'Succeeded in loading the content.'); + }); + } + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground(): void { + // Ability has back to background + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onBackground'); + } +} \ No newline at end of file diff --git a/examples/jsMultiContext/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/examples/jsMultiContext/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..fae19f9dd53d2857e2843539cbedf5bee4a34b5a --- /dev/null +++ b/examples/jsMultiContext/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -0,0 +1,16 @@ +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { BackupExtensionAbility, BundleVersion } from '@kit.CoreFileKit'; + +const DOMAIN = 0x0000; + +export default class EntryBackupAbility extends BackupExtensionAbility { + async onBackup() { + hilog.info(DOMAIN, 'testTag', 'onBackup ok'); + await Promise.resolve(); + } + + async onRestore(bundleVersion: BundleVersion) { + hilog.info(DOMAIN, 'testTag', 'onRestore ok %{public}s', JSON.stringify(bundleVersion)); + await Promise.resolve(); + } +} \ No newline at end of file diff --git a/examples/jsMultiContext/entry/src/main/ets/framework/PComponent.ets b/examples/jsMultiContext/entry/src/main/ets/framework/PComponent.ets new file mode 100644 index 0000000000000000000000000000000000000000..7b64c404fcab81da3eb95e3b72699b39ff70802f --- /dev/null +++ b/examples/jsMultiContext/entry/src/main/ets/framework/PComponent.ets @@ -0,0 +1,255 @@ +import { NodeContent } from '@kit.ArkUI'; +import { nativeDestroyPluginComponent, nativeRequirePlugins } from 'libentry.so'; +import { ComponentContent, typeNode } from '@ohos.arkui.node'; + +export const width1 : number = 200; + +@Component +export struct DatePickers { + private holderSlot = new NodeContent(); + aboutToAppear(): void { + globalThis.aaa = 'I am host.' + let obj1 = nativeRequirePlugins('car', 'InitBuilder', this.getUIContext(), '1'); + console.log('jsContext obj = ' + typeof obj1); + let holder = typeNode.createNode(this.getUIContext(), 'Column'); + holder.initialize(); + holder.addComponentContent(obj1 as ComponentContent<[]>); + + let obj2 = nativeRequirePlugins('car', 'InitBuilder4', this.getUIContext(), '2'); + console.log('jsContext obj2 = ' + typeof obj2); + holder.addComponentContent(obj2 as ComponentContent<[]>) + + this.holderSlot.addFrameNode(holder); + console.log('jsContext globalThis.aaa = ' + globalThis.aaa); + } + + aboutToDisappear(): void { + nativeDestroyPluginComponent('1'); + nativeDestroyPluginComponent('2'); + } + build() { + Column() { + ContentSlot(this.holderSlot) + } + } +} + +@Component +export struct CalendarPickers { + private holderSlot = new NodeContent(); + aboutToAppear(): void { + globalThis.aaa = 'I am host.' + let obj1 = nativeRequirePlugins('car', 'InitBuilder1', this.getUIContext(), '1'); + console.log('jsContext obj = ' + typeof obj1); + let holder = typeNode.createNode(this.getUIContext(), 'Column'); + holder.initialize(); + holder.addComponentContent(obj1 as ComponentContent<[]>); + + let obj2 = nativeRequirePlugins('car', 'InitBuilder5', this.getUIContext(), '2'); + console.log('jsContext obj2 = ' + typeof obj2); + holder.addComponentContent(obj2 as ComponentContent<[]>) + + this.holderSlot.addFrameNode(holder); + console.log('jsContext globalThis.aaa = ' + globalThis.aaa); + } + + aboutToDisappear(): void { + nativeDestroyPluginComponent('1'); + nativeDestroyPluginComponent('2'); + } + build() { + Column() { + ContentSlot(this.holderSlot) + } + } +} + +@Component +export struct TimePickers { + private holderSlot = new NodeContent(); + aboutToAppear(): void { + globalThis.aaa = 'I am host.' + let obj1 = nativeRequirePlugins('car', 'InitBuilder2', this.getUIContext(), '1'); + console.log('jsContext obj = ' + typeof obj1); + let holder = typeNode.createNode(this.getUIContext(), 'Column'); + holder.initialize(); + holder.addComponentContent(obj1 as ComponentContent<[]>); + + let obj2 = nativeRequirePlugins('car', 'InitBuilder6', this.getUIContext(), '2'); + console.log('jsContext obj2 = ' + typeof obj2); + holder.addComponentContent(obj2 as ComponentContent<[]>) + + this.holderSlot.addFrameNode(holder); + console.log('jsContext globalThis.aaa = ' + globalThis.aaa); + } + + aboutToDisappear(): void { + nativeDestroyPluginComponent('1'); + nativeDestroyPluginComponent('2'); + } + build() { + Column() { + ContentSlot(this.holderSlot) + } + } +} + +@Component +export struct TextPickers { + private holderSlot = new NodeContent(); + aboutToAppear(): void { + globalThis.aaa = 'I am host.' + let obj1 = nativeRequirePlugins('car', 'InitBuilder3', this.getUIContext(), '1'); + console.log('jsContext obj = ' + typeof obj1); + let holder = typeNode.createNode(this.getUIContext(), 'Column'); + holder.initialize(); + holder.addComponentContent(obj1 as ComponentContent<[]>); + + let obj2 = nativeRequirePlugins('car', 'InitBuilder7', this.getUIContext(), '2'); + console.log('jsContext obj2 = ' + typeof obj2); + holder.addComponentContent(obj2 as ComponentContent<[]>) + + this.holderSlot.addFrameNode(holder); + console.log('jsContext globalThis.aaa = ' + globalThis.aaa); + } + + aboutToDisappear(): void { + nativeDestroyPluginComponent('1'); + nativeDestroyPluginComponent('2'); + } + build() { + Column() { + ContentSlot(this.holderSlot) + } + } +} + +@Component +export struct ImageBuilder { + private holderSlot = new NodeContent(); + aboutToAppear(): void { + globalThis.aaa = 'I am host.' + let obj1 = nativeRequirePlugins('car', 'InitBuilder8', this.getUIContext(), '1'); + console.log('jsContext obj = ' + typeof obj1); + let holder = typeNode.createNode(this.getUIContext(), 'Column'); + holder.initialize(); + holder.addComponentContent(obj1 as ComponentContent<[]>); + + this.holderSlot.addFrameNode(holder); + console.log('jsContext globalThis.aaa = ' + globalThis.aaa); + } + + aboutToDisappear(): void { + nativeDestroyPluginComponent('1'); + } + build() { + Column() { + ContentSlot(this.holderSlot) + } + } +} + +@Component +export struct ImageAnimatorBuilder { + private holderSlot = new NodeContent(); + aboutToAppear(): void { + globalThis.aaa = 'I am host.' + let obj1 = nativeRequirePlugins('car', 'InitBuilder9', this.getUIContext(), '1'); + console.log('jsContext obj = ' + typeof obj1); + let holder = typeNode.createNode(this.getUIContext(), 'Column'); + holder.initialize(); + holder.addComponentContent(obj1 as ComponentContent<[]>); + + this.holderSlot.addFrameNode(holder); + console.log('jsContext globalThis.aaa = ' + globalThis.aaa); + } + + aboutToDisappear(): void { + nativeDestroyPluginComponent('1'); + } + build() { + Column() { + ContentSlot(this.holderSlot) + } + } +} + +@Component +export struct CounterBuilder { + private holderSlot = new NodeContent(); + aboutToAppear(): void { + globalThis.aaa = 'I am host.' + let obj1 = nativeRequirePlugins('car', 'InitBuilder10', this.getUIContext(), '1'); + console.log('jsContext obj = ' + typeof obj1); + let holder = typeNode.createNode(this.getUIContext(), 'Column'); + holder.initialize(); + holder.addComponentContent(obj1 as ComponentContent<[]>); + + this.holderSlot.addFrameNode(holder); + console.log('jsContext globalThis.aaa = ' + globalThis.aaa); + } + + aboutToDisappear(): void { + nativeDestroyPluginComponent('1'); + } + build() { + Column() { + ContentSlot(this.holderSlot) + } + } +} + +@Component +export struct PatternLockBuilder { + private holderSlot = new NodeContent(); + aboutToAppear(): void { + globalThis.aaa = 'I am host.' + let obj1 = nativeRequirePlugins('car', 'InitBuilder11', this.getUIContext(), '1'); + console.log('jsContext obj = ' + typeof obj1); + let holder = typeNode.createNode(this.getUIContext(), 'Column'); + holder.initialize(); + holder.addComponentContent(obj1 as ComponentContent<[]>); + + this.holderSlot.addFrameNode(holder); + console.log('jsContext globalThis.aaa = ' + globalThis.aaa); + } + + aboutToDisappear(): void { + nativeDestroyPluginComponent('1'); + } + build() { + Column() { + ContentSlot(this.holderSlot) + } + } +} + +@Component +export struct Texts { + private holderSlot = new NodeContent(); + aboutToAppear(): void { + globalThis.aaa = 'I am host.' + let obj1 = nativeRequirePlugins('car', 'InitBuilder12', this.getUIContext(), '1'); + console.log('jsContext obj = ' + typeof obj1); + let holder = typeNode.createNode(this.getUIContext(), 'Column'); + holder.initialize(); + holder.addComponentContent(obj1 as ComponentContent<[]>); + + let obj2 = nativeRequirePlugins('car', 'InitBuilder13', this.getUIContext(), '2'); + console.log('jsContext obj2 = ' + typeof obj2); + holder.addComponentContent(obj2 as ComponentContent<[]>) + + this.holderSlot.addFrameNode(holder); + console.log('jsContext globalThis.aaa = ' + globalThis.aaa); + } + + aboutToDisappear(): void { + nativeDestroyPluginComponent('1'); + nativeDestroyPluginComponent('2'); + } + build() { + Column() { + ContentSlot(this.holderSlot) + } + } +} \ No newline at end of file diff --git a/examples/jsMultiContext/entry/src/main/ets/framework/hms.ts b/examples/jsMultiContext/entry/src/main/ets/framework/hms.ts new file mode 100644 index 0000000000000000000000000000000000000000..beb20ea03765e821dca504059e0c051c796b8012 --- /dev/null +++ b/examples/jsMultiContext/entry/src/main/ets/framework/hms.ts @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2025 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. + */ +import { nativeRequirePlugin } from "libentry.so"; +import { hmsObj } from "./hms_ability" +export class hms { + public static requirePlugin(id: string): Promise { + return new Promise(async (resolve) => { + resolve(nativeRequirePlugin(id, hmsObj) as T); + }); + } +} \ No newline at end of file diff --git a/examples/jsMultiContext/entry/src/main/ets/framework/hms_ability.ts b/examples/jsMultiContext/entry/src/main/ets/framework/hms_ability.ts new file mode 100644 index 0000000000000000000000000000000000000000..38539b8bd46980f15bca0ce203962eda56316fe7 --- /dev/null +++ b/examples/jsMultiContext/entry/src/main/ets/framework/hms_ability.ts @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2025 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. + */ +import { fileIo } from '@kit.CoreFileKit' + +class hms_ability { + callFile(path: string) { + let result = fileIo.accessSync(path); + console.log('hms_ability callFile result = ' + result + ' , ' + globalThis.aaa); + return result; + } +} + +export const hmsObj = new hms_ability(); \ No newline at end of file diff --git a/examples/jsMultiContext/entry/src/main/ets/pages/Index.ets b/examples/jsMultiContext/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..ee5bec27bead959c3bea7561ae05ca1995a7f8d4 --- /dev/null +++ b/examples/jsMultiContext/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,29 @@ +import router from '@ohos.router'; + +interface ListCategories { + title: string, + url: string +} + +@Entry +@Component +struct Index { + @State message: string = 'Search' + private items: ListCategories[] = [ + { title: '加载插件', url: 'pages/plugins' }, + ] + + build() { + Column() { + List({ space: '10vp' }) { + ForEach(this.items, (item: ListCategories) => { + ListItem() { + Text(item.title).fontSize(16).fontWeight(FontWeight.Bold).onClick(() => { + router.pushUrl({ url: item.url }); + }) + }.width('90%').height('80vp').backgroundColor('#ff53ecd9').borderRadius(10) + }) + }.alignListItem(ListItemAlign.Center).margin({ top: '10vp' }).width('100%').height('50%') + }.width('100%').height('100%') + } +} \ No newline at end of file diff --git a/examples/jsMultiContext/entry/src/main/ets/pages/plugin1.ets b/examples/jsMultiContext/entry/src/main/ets/pages/plugin1.ets new file mode 100644 index 0000000000000000000000000000000000000000..0990695e96e267b8a113031a7adf90d78ba37369 --- /dev/null +++ b/examples/jsMultiContext/entry/src/main/ets/pages/plugin1.ets @@ -0,0 +1,11 @@ +import { DatePickers } from '../framework/PComponent' + +@Entry +@Component +struct Plugins { + build() { + Column() { + DatePickers() + } + } +} \ No newline at end of file diff --git a/examples/jsMultiContext/entry/src/main/ets/pages/plugin2.ets b/examples/jsMultiContext/entry/src/main/ets/pages/plugin2.ets new file mode 100644 index 0000000000000000000000000000000000000000..2d36aaf153e697e14e7283a72117eed0f6664fd2 --- /dev/null +++ b/examples/jsMultiContext/entry/src/main/ets/pages/plugin2.ets @@ -0,0 +1,11 @@ +import { CalendarPickers } from '../framework/PComponent' + +@Entry +@Component +struct Plugins { + build() { + Column() { + CalendarPickers() + } + } +} \ No newline at end of file diff --git a/examples/jsMultiContext/entry/src/main/ets/pages/plugin3.ets b/examples/jsMultiContext/entry/src/main/ets/pages/plugin3.ets new file mode 100644 index 0000000000000000000000000000000000000000..03d5b03d9e1afd9723305fa96cd0aa295dafe81d --- /dev/null +++ b/examples/jsMultiContext/entry/src/main/ets/pages/plugin3.ets @@ -0,0 +1,11 @@ +import { TimePickers } from '../framework/PComponent' + +@Entry +@Component +struct Plugins { + build() { + Column() { + TimePickers() + } + } +} \ No newline at end of file diff --git a/examples/jsMultiContext/entry/src/main/ets/pages/plugin4.ets b/examples/jsMultiContext/entry/src/main/ets/pages/plugin4.ets new file mode 100644 index 0000000000000000000000000000000000000000..be9108b77014b83d143a8b31688d76a9607bf9c9 --- /dev/null +++ b/examples/jsMultiContext/entry/src/main/ets/pages/plugin4.ets @@ -0,0 +1,11 @@ +import { TextPickers } from '../framework/PComponent' + +@Entry +@Component +struct Plugins { + build() { + Column() { + TextPickers() + } + } +} \ No newline at end of file diff --git a/examples/jsMultiContext/entry/src/main/ets/pages/plugin5.ets b/examples/jsMultiContext/entry/src/main/ets/pages/plugin5.ets new file mode 100644 index 0000000000000000000000000000000000000000..20b1501a83be901edd485eff8d576877771af7a4 --- /dev/null +++ b/examples/jsMultiContext/entry/src/main/ets/pages/plugin5.ets @@ -0,0 +1,16 @@ +import { ImageBuilder, ImageAnimatorBuilder } from '../framework/PComponent' + +@Entry +@Component +struct Plugins { + build() { + Column() { + Row() { + ImageBuilder() + } + Row() { + ImageAnimatorBuilder() + } + } + } +} \ No newline at end of file diff --git a/examples/jsMultiContext/entry/src/main/ets/pages/plugin6.ets b/examples/jsMultiContext/entry/src/main/ets/pages/plugin6.ets new file mode 100644 index 0000000000000000000000000000000000000000..704fcdea74dde3e393710a86f0ec4d191ceca1c1 --- /dev/null +++ b/examples/jsMultiContext/entry/src/main/ets/pages/plugin6.ets @@ -0,0 +1,12 @@ +import { CounterBuilder, PatternLockBuilder } from '../framework/PComponent' + +@Entry +@Component +struct Plugins { + build() { + Column() { + CounterBuilder() + PatternLockBuilder() + } + } +} \ No newline at end of file diff --git a/examples/jsMultiContext/entry/src/main/ets/pages/plugin7.ets b/examples/jsMultiContext/entry/src/main/ets/pages/plugin7.ets new file mode 100644 index 0000000000000000000000000000000000000000..3b88aa6dc30148940e91f78aa4b799ad8ba19e40 --- /dev/null +++ b/examples/jsMultiContext/entry/src/main/ets/pages/plugin7.ets @@ -0,0 +1,11 @@ +import { Texts } from '../framework/PComponent' + +@Entry +@Component +struct Plugins { + build() { + Column() { + Texts() + } + } +} \ No newline at end of file diff --git a/examples/jsMultiContext/entry/src/main/ets/pages/plugins.ets b/examples/jsMultiContext/entry/src/main/ets/pages/plugins.ets new file mode 100644 index 0000000000000000000000000000000000000000..5740756e620fb18de77e71472674fbcc7de7b768 --- /dev/null +++ b/examples/jsMultiContext/entry/src/main/ets/pages/plugins.ets @@ -0,0 +1,118 @@ +// main context environment +import { UIContext, CommonModifier } from '@kit.ArkUI'; +import router from '@ohos.router'; + +class MyCheckboxStyle implements ContentModifier { + public selectedColor: Color = Color.White; + + constructor(selectedColor: Color) { + this.selectedColor = selectedColor; + } + + applyContent(): WrappedBuilder<[CheckBoxConfiguration]> { + return wrapBuilder(buildCheckbox); + } +} + +@Builder +function buildCheckbox(config: CheckBoxConfiguration) { + Column({ space: 10 }) { + Text(config.name + (config.selected ? '(选中)' : '(非选中)')) + Shape() { + // 五边形复选框样式 + Path() + .width(200) + .height(60) + .commands('M100 0 L0 100 L50 200 L150 200 L200 100 Z') + .fillOpacity(0) + .strokeWidth(3) + // 红色三角图案样式 + Path() + .width(10) + .height(10) + .commands('M50 0 L100 100 L0 100 Z') + .visibility(config.selected ? Visibility.Visible : Visibility.Hidden) + .fill(config.selected ? (config.contentModifier as MyCheckboxStyle).selectedColor : Color.Black) + .stroke((config.contentModifier as MyCheckboxStyle).selectedColor) + .margin({ left: 11, top: 10 }) + } + .width(300) + .height(200) + .viewPort({ + x: 0, + y: 0, + width: 310, + height: 310 + }) + .strokeLineJoin(LineJoinStyle.Miter) + .strokeMiterLimit(5) + .onClick(() => { + // 点击后,触发复选框点击状态变化 + if (config.selected) { + config.triggerChange(false); + } else { + config.triggerChange(true); + } + }) + .margin({ left: 150 }) + } +} + +let storage: LocalStorage = new LocalStorage(); +PersistentStorage.persistProp('uiContext', undefined); + +@Entry(storage) +@Component +struct MyIndex { + @StorageLink('uiContext') p: UIContext | undefined | null = this.getUIContext(); + @State result: string = '' + private items: string[] = [ + 'DatePicker插件', + 'CalendarPicker插件', + 'TimePicker插件', + 'TextPicker插件', + 'Image插件', + 'Counter和PatternLock插件', + 'TextClock和TextTimer插件', + ] + @State modifier: ContentModifier = new MyCheckboxStyle(Color.Red); + @State click: CommonModifier = new CommonModifier().onClick(() => { + }) + + build() { + Column() { + List({ space: '10vp' }) { + ForEach(this.items, (item: string) => { + ListItem() { + Text(item) + .fontSize(16) + .fontWeight(FontWeight.Bold) + .onClick(() => { + globalThis.aaa = 'i am from host.'; + if (item === 'DatePicker插件') { + router.pushUrl({ url: 'pages/plugin1' }); + } else if (item === 'CalendarPicker插件') { + router.pushUrl({ url: 'pages/plugin2' }); + } else if (item === 'TimePicker插件') { + router.pushUrl({ url: 'pages/plugin3' }); + } else if (item === 'TextPicker插件') { + router.pushUrl({ url: 'pages/plugin4' }); + } else if (item === 'Image插件') { + router.pushUrl({ url: 'pages/plugin5' }); + } else if (item === 'Counter和PatternLock插件') { + router.pushUrl({ url: 'pages/plugin6' }); + } else if (item === 'TextClock和TextTimer插件') { + router.pushUrl({ url: 'pages/plugin7' }); + } + }) + .width('100%') + .height('100%') + .textAlign(TextAlign.Center) + + }.width('80%').height('80vp').backgroundColor('#ff53ecd9').borderRadius(10) + }) + }.alignListItem(ListItemAlign.Center).margin({ top: '10vp' }).width('100%').height('50%') + } + } +} + diff --git a/examples/jsMultiContext/entry/src/main/ets/types/CarType.ts b/examples/jsMultiContext/entry/src/main/ets/types/CarType.ts new file mode 100644 index 0000000000000000000000000000000000000000..18fb01896c9e657cd90f3b83381642d98e6f6c48 --- /dev/null +++ b/examples/jsMultiContext/entry/src/main/ets/types/CarType.ts @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 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. + */ +export type Car = { + callCar(): string; + + callCarAsync(): Promise; + + callFileIo(filePath: string); +} \ No newline at end of file diff --git a/examples/jsMultiContext/entry/src/main/module.json5 b/examples/jsMultiContext/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..fe15ce216cce50e7d8bf28fabb09e7999f3e41f3 --- /dev/null +++ b/examples/jsMultiContext/entry/src/main/module.json5 @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2025 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. + */ +{ + "module": { + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "default" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "EntryAbility", + "srcEntry": "./ets/entryability/EntryAbility.ets", + "description": "$string:EntryAbility_desc", + "icon": "$media:layered_image", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "ohos.want.action.home" + ] + } + ] + } + ], + "extensionAbilities": [ + { + "name": "EntryBackupAbility", + "srcEntry": "./ets/entrybackupability/EntryBackupAbility.ets", + "type": "backup", + "exported": false, + "metadata": [ + { + "name": "ohos.extension.backup", + "resource": "$profile:backup_config" + } + ] + } + ] + } +} \ No newline at end of file diff --git a/examples/jsMultiContext/entry/src/main/resources/base/element/color.json b/examples/jsMultiContext/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33 --- /dev/null +++ b/examples/jsMultiContext/entry/src/main/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/examples/jsMultiContext/entry/src/main/resources/base/element/float.json b/examples/jsMultiContext/entry/src/main/resources/base/element/float.json new file mode 100644 index 0000000000000000000000000000000000000000..5f0600c7083c3ac3776dcc13ce3e3f03c378fc6d --- /dev/null +++ b/examples/jsMultiContext/entry/src/main/resources/base/element/float.json @@ -0,0 +1,8 @@ +{ + "float": [ + { + "name": "page_text_font_size", + "value": "50fp" + } + ] +} \ No newline at end of file diff --git a/examples/jsMultiContext/entry/src/main/resources/base/element/string.json b/examples/jsMultiContext/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..f94595515a99e0c828807e243494f57f09251930 --- /dev/null +++ b/examples/jsMultiContext/entry/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "label" + } + ] +} \ No newline at end of file diff --git a/examples/jsMultiContext/entry/src/main/resources/base/media/background.png b/examples/jsMultiContext/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/examples/jsMultiContext/entry/src/main/resources/base/media/background.png differ diff --git a/examples/jsMultiContext/entry/src/main/resources/base/media/foreground.png b/examples/jsMultiContext/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..97014d3e10e5ff511409c378cd4255713aecd85f Binary files /dev/null and b/examples/jsMultiContext/entry/src/main/resources/base/media/foreground.png differ diff --git a/examples/jsMultiContext/entry/src/main/resources/base/media/layered_image.json b/examples/jsMultiContext/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/examples/jsMultiContext/entry/src/main/resources/base/media/layered_image.json @@ -0,0 +1,7 @@ +{ + "layered-image": + { + "background" : "$media:background", + "foreground" : "$media:foreground" + } +} \ No newline at end of file diff --git a/examples/jsMultiContext/entry/src/main/resources/base/media/startIcon.png b/examples/jsMultiContext/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/examples/jsMultiContext/entry/src/main/resources/base/media/startIcon.png differ diff --git a/examples/jsMultiContext/entry/src/main/resources/base/profile/backup_config.json b/examples/jsMultiContext/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..d742c2f96e7dd0f406f499941f3147345e998f95 --- /dev/null +++ b/examples/jsMultiContext/entry/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/examples/jsMultiContext/entry/src/main/resources/base/profile/main_pages.json b/examples/jsMultiContext/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..4b123472b704f05e15443440d4788793907dd07a --- /dev/null +++ b/examples/jsMultiContext/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,13 @@ +{ + "src": [ + "pages/Index", + "pages/plugins", + "pages/plugin1", + "pages/plugin2", + "pages/plugin3", + "pages/plugin4", + "pages/plugin5", + "pages/plugin6", + "pages/plugin7" + ] +} \ No newline at end of file diff --git a/examples/jsMultiContext/entry/src/main/resources/dark/element/color.json b/examples/jsMultiContext/entry/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..438d5bc43bb23c59c210d586b96635a72da5b64a --- /dev/null +++ b/examples/jsMultiContext/entry/src/main/resources/dark/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#000000" + } + ] +} \ No newline at end of file diff --git a/examples/jsMultiContext/entry/src/mock/Libentry.mock.ets b/examples/jsMultiContext/entry/src/mock/Libentry.mock.ets new file mode 100644 index 0000000000000000000000000000000000000000..c2171716d040a605ef6af71e90b937a945f2677d --- /dev/null +++ b/examples/jsMultiContext/entry/src/mock/Libentry.mock.ets @@ -0,0 +1,7 @@ +const NativeMock: Record = { + 'add': (a: number, b: number) => { + return a + b; + }, +}; + +export default NativeMock; \ No newline at end of file diff --git a/examples/jsMultiContext/entry/src/mock/mock-config.json5 b/examples/jsMultiContext/entry/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..98b0ae79f0090e1fc381d54c959fb32c9f7563f4 --- /dev/null +++ b/examples/jsMultiContext/entry/src/mock/mock-config.json5 @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2025 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. + */ +{ + "libentry.so": { + "source": "src/mock/Libentry.mock.ets" + } +} \ No newline at end of file diff --git a/examples/jsMultiContext/entry/src/ohosTest/ets/test/Ability.test.ets b/examples/jsMultiContext/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..85c78f67579d6e31b5f5aeea463e216b9b141048 --- /dev/null +++ b/examples/jsMultiContext/entry/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,35 @@ +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +export default function abilityTest() { + describe('ActsAbilityTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }) + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }) + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }) + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }) + it('assertContain', 0, () => { + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. + hilog.info(0x0000, 'testTag', '%{public}s', 'it begin'); + let a = 'abc'; + let b = 'b'; + // Defines a variety of assertion methods, which are used to declare expected boolean conditions. + expect(a).assertContain(b); + expect(a).assertEqual(a); + }) + }) +} \ No newline at end of file diff --git a/examples/jsMultiContext/entry/src/ohosTest/ets/test/List.test.ets b/examples/jsMultiContext/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..794c7dc4ed66bd98fa3865e07922906e2fcef545 --- /dev/null +++ b/examples/jsMultiContext/entry/src/ohosTest/ets/test/List.test.ets @@ -0,0 +1,5 @@ +import abilityTest from './Ability.test'; + +export default function testsuite() { + abilityTest(); +} \ No newline at end of file diff --git a/examples/jsMultiContext/entry/src/ohosTest/module.json5 b/examples/jsMultiContext/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..ae55a7c74de9e092f16fdbbe16f3e35fba50ef51 --- /dev/null +++ b/examples/jsMultiContext/entry/src/ohosTest/module.json5 @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2025 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. + */ +{ + "module": { + "name": "entry_test", + "type": "feature", + "deviceTypes": [ + "default" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/examples/jsMultiContext/entry/src/test/List.test.ets b/examples/jsMultiContext/entry/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..bb5b5c3731e283dd507c847560ee59bde477bbc7 --- /dev/null +++ b/examples/jsMultiContext/entry/src/test/List.test.ets @@ -0,0 +1,5 @@ +import localUnitTest from './LocalUnit.test'; + +export default function testsuite() { + localUnitTest(); +} \ No newline at end of file diff --git a/examples/jsMultiContext/entry/src/test/LocalUnit.test.ets b/examples/jsMultiContext/entry/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..165fc1615ee8618b4cb6a622f144a9a707eee99f --- /dev/null +++ b/examples/jsMultiContext/entry/src/test/LocalUnit.test.ets @@ -0,0 +1,33 @@ +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +export default function localUnitTest() { + describe('localUnitTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }); + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }); + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }); + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }); + it('assertContain', 0, () => { + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. + let a = 'abc'; + let b = 'b'; + // Defines a variety of assertion methods, which are used to declare expected boolean conditions. + expect(a).assertContain(b); + expect(a).assertEqual(a); + }); + }); +} \ No newline at end of file diff --git a/examples/jsMultiContext/hvigor/hvigor-config.json5 b/examples/jsMultiContext/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..1d24edfbfc2c718a1117749793713e7aa9e72ed5 --- /dev/null +++ b/examples/jsMultiContext/hvigor/hvigor-config.json5 @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2025 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. + */ +{ + "modelVersion": "5.0.4", + "dependencies": { + }, + "execution": { + // "analyze": "normal", /* Define the build analyze mode. Value: [ "normal" | "advanced" | false ]. Default: "normal" */ + // "daemon": true, /* Enable daemon compilation. Value: [ true | false ]. Default: true */ + // "incremental": true, /* Enable incremental compilation. Value: [ true | false ]. Default: true */ + // "parallel": true, /* Enable parallel compilation. Value: [ true | false ]. Default: true */ + // "typeCheck": false, /* Enable typeCheck. Value: [ true | false ]. Default: false */ + }, + "logging": { + // "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */ + }, + "debugging": { + // "stacktrace": false /* Disable stacktrace compilation. Value: [ true | false ]. Default: false */ + }, + "nodeOptions": { + // "maxOldSpaceSize": 8192 /* Enable nodeOptions maxOldSpaceSize compilation. Unit M. Used for the daemon process. Default: 8192*/ + // "exposeGC": true /* Enable to trigger garbage collection explicitly. Default: true*/ + } +} diff --git a/examples/jsMultiContext/hvigorfile.ts b/examples/jsMultiContext/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..ae9086af35844176c08f1be3772d081d95d267c6 --- /dev/null +++ b/examples/jsMultiContext/hvigorfile.ts @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 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. + */ +import { appTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: appTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins: [] /* Custom plugin to extend the functionality of Hvigor. */ +} \ No newline at end of file diff --git a/examples/jsMultiContext/oh-package-lock.json5 b/examples/jsMultiContext/oh-package-lock.json5 new file mode 100644 index 0000000000000000000000000000000000000000..519ec40315a8b895ec1190e0003d62cf0988a8e3 --- /dev/null +++ b/examples/jsMultiContext/oh-package-lock.json5 @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2025 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. + */ +{ + "meta": { + "stableOrder": true + }, + "lockfileVersion": 3, + "ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.", + "specifiers": { + "@ohos/hamock@1.0.0": "@ohos/hamock@1.0.0", + "@ohos/hypium@1.0.21": "@ohos/hypium@1.0.21" + }, + "packages": { + "@ohos/hamock@1.0.0": { + "name": "@ohos/hamock", + "version": "1.0.0", + "integrity": "sha512-K6lDPYc6VkKe6ZBNQa9aoG+ZZMiwqfcR/7yAVFSUGIuOAhPvCJAo9+t1fZnpe0dBRBPxj2bxPPbKh69VuyAtDg==", + "resolved": "https://ohpm.openharmony.cn/ohpm/@ohos/hamock/-/hamock-1.0.0.har", + "registryType": "ohpm" + }, + "@ohos/hypium@1.0.21": { + "name": "@ohos/hypium", + "version": "1.0.21", + "integrity": "sha512-iyKGMXxE+9PpCkqEwu0VykN/7hNpb+QOeIuHwkmZnxOpI+dFZt6yhPB7k89EgV1MiSK/ieV/hMjr5Z2mWwRfMQ==", + "resolved": "https://ohpm.openharmony.cn/ohpm/@ohos/hypium/-/hypium-1.0.21.har", + "registryType": "ohpm" + } + } +} \ No newline at end of file diff --git a/examples/jsMultiContext/oh-package.json5 b/examples/jsMultiContext/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..acafbdcb2d3af1556ca0fe214a93adf415fa82d7 --- /dev/null +++ b/examples/jsMultiContext/oh-package.json5 @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2025 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. + */ +{ + "modelVersion": "5.0.4", + "description": "Please describe the basic information.", + "dependencies": { + }, + "devDependencies": { + "@ohos/hypium": "1.0.21", + "@ohos/hamock": "1.0.0" + } +}