1 /*
2 * Copyright (c) 2025 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 #include "frameworks/core/interfaces/native/runtime/runtime_init.h"
16
17 #include "core/pipeline_ng/pipeline_context.h"
18 #include "frameworks/bridge/declarative_frontend/engine/jsi/jsi_declarative_engine.h"
19 #include "interfaces/inner_api/ace_kit/include/ui/base/utils/utils.h"
20
21 namespace OHOS::Ace::RuntimeInit {
22
RegisterViews(void * nativeArkEngine)23 void RegisterViews(void* nativeArkEngine)
24 {
25 auto pipeline = NG::PipelineContext::GetCurrentContextSafely();
26 if (pipeline && !pipeline->CheckThreadSafe()) {
27 LOGF_ABORT("RegisterViews doesn't run on UI thread");
28 }
29 Framework::JsiDeclarativeEngineInstance::PreloadAceModuleForCustomRuntime(nativeArkEngine);
30 }
31
NotifyArkTSEnvDestroy(void * nativeArkEngine)32 void NotifyArkTSEnvDestroy(void* nativeArkEngine)
33 {
34 auto pipeline = NG::PipelineContext::GetCurrentContextSafely();
35 if (pipeline && !pipeline->CheckThreadSafe()) {
36 LOGF_ABORT("NotifyArkTSEnvDestroy doesn't run on UI thread");
37 }
38 CHECK_NULL_VOID(nativeArkEngine);
39 Framework::JsiDeclarativeEngineInstance::RemoveInvalidEnv(nativeArkEngine);
40 }
41
GetRuntimeInit()42 const ArkUIRuntimeInit* GetRuntimeInit()
43 {
44 CHECK_INITIALIZED_FIELDS_BEGIN(); // don't move this line
45 static const ArkUIRuntimeInit modifier = {
46 .registerViews = RegisterViews,
47 .notifyArkTSEnvDestroy = NotifyArkTSEnvDestroy,
48 };
49 CHECK_INITIALIZED_FIELDS_END(modifier, 0, 0, 0); // don't move this line
50 return &modifier;
51 }
52 }
53