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 
18 namespace OHOS::Ace::Napi {
19 static constexpr uint32_t DEFAULT = 0;
20 static constexpr uint32_t TOP_MOST = 1;
21 static constexpr uint32_t SYSTEM_TOP_MOST = 2;
PromptActionExport(napi_env env, napi_value exports)22 static napi_value PromptActionExport(napi_env env, napi_value exports)
23 {
24     napi_value showMode = nullptr;
25     napi_create_object(env, &showMode);
26     napi_value prop = nullptr;
27     napi_create_uint32(env, DEFAULT, &prop);
28     napi_set_named_property(env, showMode, "DEFAULT", prop);
29     napi_create_uint32(env, TOP_MOST, &prop);
30     napi_set_named_property(env, showMode, "TOP_MOST", prop);
31     napi_create_uint32(env, SYSTEM_TOP_MOST, &prop);
32     napi_set_named_property(env, showMode, "SYSTEM_TOP_MOST", prop);
33 
34     napi_property_descriptor promptDesc[] = {
35         DECLARE_NAPI_FUNCTION("showToast", JSPromptShowToast),
36         DECLARE_NAPI_FUNCTION("openToast", JSPromptOpenToast),
37         DECLARE_NAPI_FUNCTION("closeToast", JSPromptCloseToast),
38         DECLARE_NAPI_FUNCTION("showDialog", JSPromptShowDialog),
39         DECLARE_NAPI_FUNCTION("showActionMenu", JSPromptShowActionMenu),
40         DECLARE_NAPI_FUNCTION("openCustomDialog", JSPromptOpenCustomDialog),
41         DECLARE_NAPI_FUNCTION("updateCustomDialog", JSPromptUpdateCustomDialog),
42         DECLARE_NAPI_FUNCTION("closeCustomDialog", JSPromptCloseCustomDialog),
43         DECLARE_NAPI_PROPERTY("ToastShowMode", showMode),
44     };
45     NAPI_CALL(env, napi_define_properties(env, exports, sizeof(promptDesc) / sizeof(promptDesc[0]), promptDesc));
46     return exports;
47 }
48 
49 static napi_module promptActionModule = {
50     .nm_version = 1,
51     .nm_flags = 0,
52     .nm_filename = nullptr,
53     .nm_register_func = PromptActionExport,
54     .nm_modname = "promptAction",
55     .nm_priv = ((void*)0),
56     .reserved = { 0 },
57 };
58 
PromptActionRegister()59 extern "C" __attribute__((constructor)) void PromptActionRegister()
60 {
61     napi_module_register(&promptActionModule);
62 }
63 
64 // compatible with api8
65 static napi_module promptModule = {
66     .nm_version = 1,
67     .nm_flags = 0,
68     .nm_filename = nullptr,
69     .nm_register_func = PromptActionExport,
70     .nm_modname = "prompt",
71     .nm_priv = ((void*)0),
72     .reserved = { 0 },
73 };
74 
PromptRegister()75 extern "C" __attribute__((constructor)) void PromptRegister()
76 {
77     napi_module_register(&promptModule);
78 }
79 } // namespace OHOS::Ace::Napi
80