1 /*
2  * Copyright (c) 2021-2022 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 "init.h"
17 #include "ans_template.h"
18 #include "cancel.h"
19 #include "constant.h"
20 #include "display_badge.h"
21 #include "distributed.h"
22 #include "disturb_mode.h"
23 #include "enable_notification.h"
24 #include "get_active.h"
25 #include "pixel_map_napi.h"
26 #include "publish.h"
27 #include "remove.h"
28 #include "slot.h"
29 #include "subscribe.h"
30 #include "unsubscribe.h"
31 
32 namespace OHOS {
33 namespace NotificationNapi {
34 using namespace OHOS::Notification;
35 
36 EXTERN_C_START
37 
NotificationInit(napi_env env,napi_value exports)38 napi_value NotificationInit(napi_env env, napi_value exports)
39 {
40     ANS_LOGI("notificationInit start");
41 
42     napi_property_descriptor desc[] = {
43         DECLARE_NAPI_FUNCTION("subscribe", Subscribe),
44         DECLARE_NAPI_FUNCTION("unsubscribe", Unsubscribe),
45         DECLARE_NAPI_FUNCTION("publish", Publish),
46         DECLARE_NAPI_FUNCTION("publishAsBundle", PublishAsBundle),
47         DECLARE_NAPI_FUNCTION("remove", Remove),
48         DECLARE_NAPI_FUNCTION("removeAll", RemoveAll),
49         DECLARE_NAPI_FUNCTION("getAllActiveNotifications", GetAllActiveNotifications),
50         DECLARE_NAPI_FUNCTION("getActiveNotifications", GetActiveNotifications),
51         DECLARE_NAPI_FUNCTION("getActiveNotificationCount", GetActiveNotificationCount),
52         DECLARE_NAPI_FUNCTION("cancel", Cancel),
53         DECLARE_NAPI_FUNCTION("cancelAll", CancelAll),
54         DECLARE_NAPI_FUNCTION("cancelGroup", CancelGroup),
55         DECLARE_NAPI_FUNCTION("cancelAsBundle", CancelAsBundle),
56         DECLARE_NAPI_FUNCTION("addSlot", AddSlot),
57         DECLARE_NAPI_FUNCTION("addSlots", AddSlots),
58         DECLARE_NAPI_FUNCTION("setSlotByBundle", SetSlotByBundle),
59         DECLARE_NAPI_FUNCTION("getSlot", GetSlot),
60         DECLARE_NAPI_FUNCTION("getSlotNumByBundle", GetSlotNumByBundle),
61         DECLARE_NAPI_FUNCTION("getSlots", GetSlots),
62         DECLARE_NAPI_FUNCTION("getSlotsByBundle", GetSlotsByBundle),
63         DECLARE_NAPI_FUNCTION("removeSlot", RemoveSlot),
64         DECLARE_NAPI_FUNCTION("removeAllSlots", RemoveAllSlots),
65         DECLARE_NAPI_FUNCTION("removeGroupByBundle", RemoveGroupByBundle),
66         DECLARE_NAPI_FUNCTION("enableNotification", EnableNotification),
67         DECLARE_NAPI_FUNCTION("isNotificationEnabled", IsNotificationEnabled),
68         DECLARE_NAPI_FUNCTION("requestEnableNotification", RequestEnableNotification),
69         DECLARE_NAPI_FUNCTION("displayBadge", DisplayBadge),
70         DECLARE_NAPI_FUNCTION("isBadgeDisplayed", IsBadgeDisplayed),
71         DECLARE_NAPI_FUNCTION("setDoNotDisturbDate", SetDoNotDisturbDate),
72         DECLARE_NAPI_FUNCTION("getDoNotDisturbDate", GetDoNotDisturbDate),
73         DECLARE_NAPI_FUNCTION("supportDoNotDisturbMode", SupportDoNotDisturbMode),
74         DECLARE_NAPI_FUNCTION("isSupportTemplate", IsSupportTemplate),
75         DECLARE_NAPI_FUNCTION("isDistributedEnabled", IsDistributedEnabled),
76         DECLARE_NAPI_FUNCTION("enableDistributed", EnableDistributed),
77         DECLARE_NAPI_FUNCTION("enableDistributedByBundle", EnableDistributedByBundle),
78         DECLARE_NAPI_FUNCTION("enableDistributedSelf", EnableDistributedSelf),
79         DECLARE_NAPI_FUNCTION("isDistributedEnabledByBundle", IsDistributedEnableByBundle),
80         DECLARE_NAPI_FUNCTION("getDeviceRemindType", GetDeviceRemindType),
81         DECLARE_NAPI_FUNCTION("show", ShowNotification),
82         DECLARE_NAPI_FUNCTION("enableNotificationSlot", EnableNotificationSlot),
83         DECLARE_NAPI_FUNCTION("isNotificationSlotEnabled", IsEnableNotificationSlot),
84         DECLARE_NAPI_FUNCTION("setSyncNotificationEnabledWithoutApp", SetSyncNotificationEnabledWithoutApp),
85         DECLARE_NAPI_FUNCTION("getSyncNotificationEnabledWithoutApp", GetSyncNotificationEnabledWithoutApp),
86     };
87 
88     NAPI_CALL(env, napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc));
89 
90     return exports;
91 }
92 
93 /*
94  * Module export function
95  */
Init(napi_env env,napi_value exports)96 static napi_value Init(napi_env env, napi_value exports)
97 {
98     /*
99      * Propertise define
100      */
101     ANS_LOGI("libnotification Init start");
102     NotificationInit(env, exports);
103     ConstantInit(env, exports);
104 
105     return exports;
106 }
107 
108 /*
109  * Module register function
110  */
RegisterModule(void)111 __attribute__((constructor)) void RegisterModule(void)
112 {
113     ANS_LOGI("libnotification register start");
114     napi_module_register(&_module);
115 }
116 EXTERN_C_END
117 }  // namespace NotificationNapi
118 }  // namespace OHOS