1 /*
2  * Copyright (c) 2023 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 
16 #include <cstdio>
17 #include <cstring>
18 #include <pthread.h>
19 #include <unistd.h>
20 
21 #include "app_log_wrapper.h"
22 #include "js_app_overlay.h"
23 
24 namespace OHOS {
25 namespace AppExecFwk {
OverlayExport(napi_env env,napi_value exports)26 static napi_value OverlayExport(napi_env env, napi_value exports)
27 {
28     APP_LOGI("export overlay begin");
29     napi_property_descriptor desc[] = {
30         DECLARE_NAPI_FUNCTION("setOverlayEnabled", SetOverlayEnabled),
31         DECLARE_NAPI_FUNCTION("setOverlayEnabledByBundleName", SetOverlayEnabledByBundleName),
32         DECLARE_NAPI_FUNCTION("getOverlayModuleInfo", GetOverlayModuleInfo),
33         DECLARE_NAPI_FUNCTION("getTargetOverlayModuleInfos", GetTargetOverlayModuleInfos),
34         DECLARE_NAPI_FUNCTION("getOverlayModuleInfoByBundleName", GetOverlayModuleInfoByBundleName),
35         DECLARE_NAPI_FUNCTION("getTargetOverlayModuleInfosByBundleName", GetTargetOverlayModuleInfosByBundleName),
36     };
37 
38     NAPI_CALL(env, napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc));
39     APP_LOGD("init js overlay success");
40     return exports;
41 }
42 
43 static napi_module app_overlay_module = {
44     .nm_version = 1,
45     .nm_flags = 0,
46     .nm_filename = nullptr,
47     .nm_register_func = OverlayExport,
48     .nm_modname = "bundle.overlay",
49     .nm_priv = ((void *)0),
50     .reserved = {0}
51 };
52 
AppOverlayRegister(void)53 extern "C" __attribute__((constructor)) void AppOverlayRegister(void)
54 {
55     napi_module_register(&app_overlay_module);
56 }
57 }
58 }