• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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;
PromptExport(napi_env env,napi_value exports)22 static napi_value PromptExport(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("showDialog", JSPromptShowDialog),
37         DECLARE_NAPI_FUNCTION("showActionMenu", JSPromptShowActionMenu),
38         DECLARE_NAPI_FUNCTION("openCustomDialog", JSPromptOpenCustomDialog),
39         DECLARE_NAPI_FUNCTION("updateCustomDialog", JSPromptUpdateCustomDialog),
40         DECLARE_NAPI_FUNCTION("closeCustomDialog", JSPromptCloseCustomDialog),
41         DECLARE_NAPI_PROPERTY("ToastShowMode", showMode),
42     };
43     NAPI_CALL(env, napi_define_properties(env, exports, sizeof(promptDesc) / sizeof(promptDesc[0]), promptDesc));
44     return exports;
45 }
46 
47 // compatible with api8
48 static napi_module promptModule = {
49     .nm_version = 1,
50     .nm_flags = 0,
51     .nm_filename = nullptr,
52     .nm_register_func = PromptExport,
53     .nm_modname = "prompt",
54     .nm_priv = ((void*)0),
55     .reserved = { 0 },
56 };
57 
PromptRegister()58 extern "C" __attribute__((constructor)) void PromptRegister()
59 {
60     napi_module_register(&promptModule);
61 }
62 } // namespace OHOS::Ace::Napi
63