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