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 "interfaces/napi/kits/promptaction/js_level_order.h"
17 #include "interfaces/napi/kits/promptaction/js_prompt_controller.h"
18 #include "interfaces/napi/kits/promptaction/prompt_action.h"
19 #include "interfaces/napi/kits/utils/napi_utils.h"
20
21 extern const char _binary_promptaction_js_start[];
22 extern const char _binary_promptaction_abc_start[];
23 #if !defined(IOS_PLATFORM)
24 extern const char _binary_promptaction_js_end[];
25 extern const char _binary_promptaction_abc_end[];
26 #else
27 extern const char* _binary_promptaction_js_end;
28 extern const char* _binary_promptaction_abc_end;
29 #endif
30
31 namespace OHOS::Ace::Napi {
32 static constexpr uint32_t DEFAULT = 0;
33 static constexpr uint32_t TOP_MOST = 1;
34 static constexpr uint32_t SYSTEM_TOP_MOST = 2;
PromptActionExport(napi_env env,napi_value exports)35 static napi_value PromptActionExport(napi_env env, napi_value exports)
36 {
37 napi_value showMode = nullptr;
38 napi_create_object(env, &showMode);
39 napi_value prop = nullptr;
40 napi_create_uint32(env, DEFAULT, &prop);
41 napi_set_named_property(env, showMode, "DEFAULT", prop);
42 napi_create_uint32(env, TOP_MOST, &prop);
43 napi_set_named_property(env, showMode, "TOP_MOST", prop);
44 napi_create_uint32(env, SYSTEM_TOP_MOST, &prop);
45 napi_set_named_property(env, showMode, "SYSTEM_TOP_MOST", prop);
46
47 napi_property_descriptor promptDesc[] = {
48 DECLARE_NAPI_FUNCTION("showToast", JSPromptShowToast),
49 DECLARE_NAPI_FUNCTION("openToast", JSPromptOpenToast),
50 DECLARE_NAPI_FUNCTION("closeToast", JSPromptCloseToast),
51 DECLARE_NAPI_FUNCTION("showDialog", JSPromptShowDialog),
52 DECLARE_NAPI_FUNCTION("showActionMenu", JSPromptShowActionMenu),
53 DECLARE_NAPI_FUNCTION("openCustomDialog", JSPromptOpenCustomDialog),
54 DECLARE_NAPI_FUNCTION("openCustomDialogWithController", JSPromptOpenCustomDialogWithController),
55 DECLARE_NAPI_FUNCTION("presentCustomDialog", JSPromptPresentCustomDialog),
56 DECLARE_NAPI_FUNCTION("updateCustomDialog", JSPromptUpdateCustomDialog),
57 DECLARE_NAPI_FUNCTION("closeCustomDialog", JSPromptCloseCustomDialog),
58 DECLARE_NAPI_PROPERTY("ToastShowMode", showMode),
59 };
60 NAPI_CALL(env, napi_define_properties(env, exports, sizeof(promptDesc) / sizeof(promptDesc[0]), promptDesc));
61 NAPI_CALL(env, JSPromptController::Define(env, exports));
62 NAPI_CALL(env, JSLevelOrder::Define(env, exports));
63 return exports;
64 }
65
NAPI_promptaction_GetJSCode(const char ** buf,int * bufLen)66 extern "C" __attribute__((visibility("default"))) void NAPI_promptaction_GetJSCode(const char** buf, int* bufLen)
67 {
68 if (buf != nullptr) {
69 *buf = _binary_promptaction_js_start;
70 }
71
72 if (bufLen != nullptr) {
73 *bufLen = _binary_promptaction_js_end - _binary_promptaction_js_start;
74 }
75 }
76
NAPI_promptaction_GetABCCode(const char ** buf,int * buflen)77 extern "C" __attribute__((visibility("default"))) void NAPI_promptaction_GetABCCode(const char** buf, int* buflen)
78 {
79 if (buf != nullptr) {
80 *buf = _binary_promptaction_abc_start;
81 }
82 if (buflen != nullptr) {
83 *buflen = _binary_promptaction_abc_end - _binary_promptaction_abc_start;
84 }
85 }
86
87 static napi_module_with_js promptActionModule = {
88 .nm_version = 1,
89 .nm_flags = 0,
90 .nm_filename = nullptr,
91 .nm_register_func = PromptActionExport,
92 .nm_modname = "promptAction",
93 .nm_priv = ((void*)0),
94 .nm_get_abc_code = NAPI_promptaction_GetABCCode,
95 .nm_get_js_code = NAPI_promptaction_GetJSCode,
96 };
97
PromptActionRegister()98 extern "C" __attribute__((constructor)) void PromptActionRegister()
99 {
100 napi_module_with_js_register(&promptActionModule);
101 }
102 } // namespace OHOS::Ace::Napi
103