• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 "constant.h"
17 
18 namespace OHOS {
19 namespace NotificationNapi {
20 using namespace OHOS::Notification;
21 
SetNamedPropertyByInteger(napi_env env,napi_value dstObj,int32_t objName,const char * propName)22 void SetNamedPropertyByInteger(napi_env env, napi_value dstObj, int32_t objName, const char *propName)
23 {
24     napi_value prop = nullptr;
25     if (napi_create_int32(env, objName, &prop) == napi_ok) {
26         napi_set_named_property(env, dstObj, propName, prop);
27     }
28 }
29 
RemoveReasonInit(napi_env env,napi_value exports)30 napi_value RemoveReasonInit(napi_env env, napi_value exports)
31 {
32     ANS_LOGI("%{public}s, called", __func__);
33 
34     napi_value obj = nullptr;
35     napi_create_object(env, &obj);
36 
37     SetNamedPropertyByInteger(env, obj, (int32_t)RemoveReason::CLICK_REASON_REMOVE, "CLICK_REASON_REMOVE");
38     SetNamedPropertyByInteger(env, obj, (int32_t)RemoveReason::CANCEL_REASON_REMOVE, "CANCEL_REASON_REMOVE");
39 
40     napi_property_descriptor exportFuncs[] = {
41         DECLARE_NAPI_PROPERTY("RemoveReason", obj),
42     };
43 
44     napi_define_properties(env, exports, sizeof(exportFuncs) / sizeof(*exportFuncs), exportFuncs);
45     return exports;
46 }
47 
SlotTypeInit(napi_env env,napi_value exports)48 napi_value SlotTypeInit(napi_env env, napi_value exports)
49 {
50     ANS_LOGI("%{public}s, called", __func__);
51 
52     napi_value obj = nullptr;
53     napi_create_object(env, &obj);
54 
55     SetNamedPropertyByInteger(env, obj, (int32_t)SlotType::UNKNOWN_TYPE, "UNKNOWN_TYPE");
56     SetNamedPropertyByInteger(env, obj, (int32_t)SlotType::SOCIAL_COMMUNICATION, "SOCIAL_COMMUNICATION");
57     SetNamedPropertyByInteger(env, obj, (int32_t)SlotType::SERVICE_INFORMATION, "SERVICE_INFORMATION");
58     SetNamedPropertyByInteger(env, obj, (int32_t)SlotType::CONTENT_INFORMATION, "CONTENT_INFORMATION");
59     SetNamedPropertyByInteger(env, obj, (int32_t)SlotType::OTHER_TYPES, "OTHER_TYPES");
60 
61     napi_property_descriptor exportFuncs[] = {
62         DECLARE_NAPI_PROPERTY("SlotType", obj),
63     };
64 
65     napi_define_properties(env, exports, sizeof(exportFuncs) / sizeof(*exportFuncs), exportFuncs);
66     return exports;
67 }
68 
SlotLevelInit(napi_env env,napi_value exports)69 napi_value SlotLevelInit(napi_env env, napi_value exports)
70 {
71     ANS_LOGI("%{public}s, called", __func__);
72 
73     napi_value obj = nullptr;
74     napi_create_object(env, &obj);
75 
76     SetNamedPropertyByInteger(env, obj, (int32_t)SlotLevel::LEVEL_NONE, "LEVEL_NONE");
77     SetNamedPropertyByInteger(env, obj, (int32_t)SlotLevel::LEVEL_MIN, "LEVEL_MIN");
78     SetNamedPropertyByInteger(env, obj, (int32_t)SlotLevel::LEVEL_LOW, "LEVEL_LOW");
79     SetNamedPropertyByInteger(env, obj, (int32_t)SlotLevel::LEVEL_DEFAULT, "LEVEL_DEFAULT");
80     SetNamedPropertyByInteger(env, obj, (int32_t)SlotLevel::LEVEL_HIGH, "LEVEL_HIGH");
81 
82     napi_property_descriptor exportFuncs[] = {
83         DECLARE_NAPI_PROPERTY("SlotLevel", obj),
84     };
85 
86     napi_define_properties(env, exports, sizeof(exportFuncs) / sizeof(*exportFuncs), exportFuncs);
87     return exports;
88 }
89 
SemanticActionButtonInit(napi_env env,napi_value exports)90 napi_value SemanticActionButtonInit(napi_env env, napi_value exports)
91 {
92     ANS_LOGI("%{public}s, called", __func__);
93 
94     napi_value obj = nullptr;
95     napi_create_object(env, &obj);
96 
97     SetNamedPropertyByInteger(env, obj, (int32_t)SemanticActionButton::NONE_ACTION_BUTTON, "NONE_ACTION_BUTTON");
98     SetNamedPropertyByInteger(env, obj, (int32_t)SemanticActionButton::REPLY_ACTION_BUTTON, "REPLY_ACTION_BUTTON");
99     SetNamedPropertyByInteger(env, obj, (int32_t)SemanticActionButton::READ_ACTION_BUTTON, "READ_ACTION_BUTTON");
100     SetNamedPropertyByInteger(
101         env, obj, (int32_t)SemanticActionButton::UNREAD_ACTION_BUTTON, "UNREAD_ACTION_BUTTON");
102     SetNamedPropertyByInteger(
103         env, obj, (int32_t)SemanticActionButton::DELETE_ACTION_BUTTON, "DELETE_ACTION_BUTTON");
104     SetNamedPropertyByInteger(
105         env, obj, (int32_t)SemanticActionButton::ARCHIVE_ACTION_BUTTON, "ARCHIVE_ACTION_BUTTON");
106     SetNamedPropertyByInteger(
107         env, obj, (int32_t)SemanticActionButton::MUTE_ACTION_BUTTON, "MUTE_ACTION_BUTTON");
108     SetNamedPropertyByInteger(
109         env, obj, (int32_t)SemanticActionButton::UNMUTE_ACTION_BUTTON, "UNMUTE_ACTION_BUTTON");
110     SetNamedPropertyByInteger(
111         env, obj, (int32_t)SemanticActionButton::THUMBS_UP_ACTION_BUTTON, "THUMBS_UP_ACTION_BUTTON");
112     SetNamedPropertyByInteger(
113         env, obj, (int32_t)SemanticActionButton::THUMBS_DOWN_ACTION_BUTTON, "THUMBS_DOWN_ACTION_BUTTON");
114     SetNamedPropertyByInteger(env, obj, (int32_t)SemanticActionButton::CALL_ACTION_BUTTON, "CALL_ACTION_BUTTON");
115 
116     napi_property_descriptor exportFuncs[] = {
117         DECLARE_NAPI_PROPERTY("SemanticActionButton", obj),
118     };
119 
120     napi_define_properties(env, exports, sizeof(exportFuncs) / sizeof(*exportFuncs), exportFuncs);
121     return exports;
122 }
123 
InputsSourceInit(napi_env env,napi_value exports)124 napi_value InputsSourceInit(napi_env env, napi_value exports)
125 {
126     ANS_LOGI("%{public}s, called", __func__);
127 
128     napi_value obj = nullptr;
129     napi_create_object(env, &obj);
130 
131     SetNamedPropertyByInteger(env, obj, (int32_t)InputsSource::FREE_FORM_INPUT, "FREE_FORM_INPUT");
132     SetNamedPropertyByInteger(env, obj, (int32_t)InputsSource::OPTION, "OPTION");
133 
134     napi_property_descriptor exportFuncs[] = {
135         DECLARE_NAPI_PROPERTY("InputsSource", obj),
136     };
137 
138     napi_define_properties(env, exports, sizeof(exportFuncs) / sizeof(*exportFuncs), exportFuncs);
139     return exports;
140 }
141 
DoNotDisturbMode(napi_env env,napi_value exports)142 napi_value DoNotDisturbMode(napi_env env, napi_value exports)
143 {
144     ANS_LOGI("%{public}s, called", __func__);
145 
146     napi_value obj = nullptr;
147     napi_create_object(env, &obj);
148 
149     SetNamedPropertyByInteger(env, obj, (int32_t)DisturbMode::ALLOW_UNKNOWN, "ALLOW_UNKNOWN");
150     SetNamedPropertyByInteger(env, obj, (int32_t)DisturbMode::ALLOW_ALL, "ALLOW_ALL");
151     SetNamedPropertyByInteger(env, obj, (int32_t)DisturbMode::ALLOW_PRIORITY, "ALLOW_PRIORITY");
152     SetNamedPropertyByInteger(env, obj, (int32_t)DisturbMode::ALLOW_NONE, "ALLOW_NONE");
153     SetNamedPropertyByInteger(env, obj, (int32_t)DisturbMode::ALLOW_ALARMS, "ALLOW_ALARMS");
154 
155     napi_property_descriptor exportFuncs[] = {
156         DECLARE_NAPI_PROPERTY("DoNotDisturbMode", obj),
157     };
158 
159     napi_define_properties(env, exports, sizeof(exportFuncs) / sizeof(*exportFuncs), exportFuncs);
160     return exports;
161 }
162 
InputEditTypeInit(napi_env env,napi_value exports)163 napi_value InputEditTypeInit(napi_env env, napi_value exports)
164 {
165     ANS_LOGI("%{public}s, called", __func__);
166 
167     napi_value obj = nullptr;
168     napi_create_object(env, &obj);
169 
170     SetNamedPropertyByInteger(env, obj, (int32_t)InputEditType::EDIT_AUTO, "EDIT_AUTO");
171     SetNamedPropertyByInteger(env, obj, (int32_t)InputEditType::EDIT_DISABLED, "EDIT_DISABLED");
172     SetNamedPropertyByInteger(env, obj, (int32_t)InputEditType::EDIT_ENABLED, "EDIT_ENABLED");
173 
174     napi_property_descriptor exportFuncs[] = {
175         DECLARE_NAPI_PROPERTY("InputEditType", obj),
176     };
177 
178     napi_define_properties(env, exports, sizeof(exportFuncs) / sizeof(*exportFuncs), exportFuncs);
179     return exports;
180 }
181 
ContentTypeInit(napi_env env,napi_value exports)182 napi_value ContentTypeInit(napi_env env, napi_value exports)
183 {
184     ANS_LOGI("%{public}s, called", __func__);
185 
186     napi_value obj = nullptr;
187     napi_create_object(env, &obj);
188 
189     SetNamedPropertyByInteger(
190         env, obj, (int32_t)ContentType::NOTIFICATION_CONTENT_BASIC_TEXT, "NOTIFICATION_CONTENT_BASIC_TEXT");
191     SetNamedPropertyByInteger(
192         env, obj, (int32_t)ContentType::NOTIFICATION_CONTENT_LONG_TEXT, "NOTIFICATION_CONTENT_LONG_TEXT");
193     SetNamedPropertyByInteger(
194         env, obj, (int32_t)ContentType::NOTIFICATION_CONTENT_PICTURE, "NOTIFICATION_CONTENT_PICTURE");
195     SetNamedPropertyByInteger(
196         env, obj, (int32_t)ContentType::NOTIFICATION_CONTENT_CONVERSATION, "NOTIFICATION_CONTENT_CONVERSATION");
197     SetNamedPropertyByInteger(
198         env, obj, (int32_t)ContentType::NOTIFICATION_CONTENT_MULTILINE, "NOTIFICATION_CONTENT_MULTILINE");
199 
200     napi_property_descriptor exportFuncs[] = {
201         DECLARE_NAPI_PROPERTY("ContentType", obj),
202     };
203 
204     napi_define_properties(env, exports, sizeof(exportFuncs) / sizeof(*exportFuncs), exportFuncs);
205     return exports;
206 }
207 
DoNotDisturbTypeInit(napi_env env,napi_value exports)208 napi_value DoNotDisturbTypeInit(napi_env env, napi_value exports)
209 {
210     ANS_LOGI("%{public}s, called", __func__);
211 
212     napi_value obj = nullptr;
213     napi_create_object(env, &obj);
214 
215     SetNamedPropertyByInteger(env, obj, (int32_t)DoNotDisturbType::TYPE_NONE, "TYPE_NONE");
216     SetNamedPropertyByInteger(env, obj, (int32_t)DoNotDisturbType::TYPE_ONCE, "TYPE_ONCE");
217     SetNamedPropertyByInteger(env, obj, (int32_t)DoNotDisturbType::TYPE_DAILY, "TYPE_DAILY");
218     SetNamedPropertyByInteger(env, obj, (int32_t)DoNotDisturbType::TYPE_CLEARLY, "TYPE_CLEARLY");
219 
220     napi_property_descriptor exportFuncs[] = {
221         DECLARE_NAPI_PROPERTY("DoNotDisturbType", obj),
222     };
223 
224     napi_define_properties(env, exports, sizeof(exportFuncs) / sizeof(*exportFuncs), exportFuncs);
225     return exports;
226 }
227 
DeviceRemindTypeInit(napi_env env,napi_value exports)228 napi_value DeviceRemindTypeInit(napi_env env, napi_value exports)
229 {
230     ANS_LOGI("%{public}s, called", __func__);
231 
232     napi_value obj = nullptr;
233     napi_create_object(env, &obj);
234 
235     SetNamedPropertyByInteger(env, obj, (int32_t)DeviceRemindType::IDLE_DONOT_REMIND, "IDLE_DONOT_REMIND");
236     SetNamedPropertyByInteger(env, obj, (int32_t)DeviceRemindType::IDLE_REMIND, "IDLE_REMIND");
237     SetNamedPropertyByInteger(env, obj, (int32_t)DeviceRemindType::ACTIVE_DONOT_REMIND, "ACTIVE_DONOT_REMIND");
238     SetNamedPropertyByInteger(env, obj, (int32_t)DeviceRemindType::ACTIVE_REMIND, "ACTIVE_REMIND");
239 
240     napi_property_descriptor exportFuncs[] = {
241         DECLARE_NAPI_PROPERTY("DeviceRemindType", obj),
242     };
243 
244     napi_define_properties(env, exports, sizeof(exportFuncs) / sizeof(*exportFuncs), exportFuncs);
245     return exports;
246 }
247 
SourceTypeInit(napi_env env,napi_value exports)248 napi_value SourceTypeInit(napi_env env, napi_value exports)
249 {
250     ANS_LOGI("%{public}s, called", __func__);
251 
252     napi_value obj = nullptr;
253     napi_create_object(env, &obj);
254 
255     SetNamedPropertyByInteger(env, obj, (int32_t)SourceType::TYPE_NORMAL, "TYPE_NORMAL");
256     SetNamedPropertyByInteger(env, obj, (int32_t)SourceType::TYPE_CONTINUOUS, "TYPE_CONTINUOUS");
257     SetNamedPropertyByInteger(env, obj, (int32_t)SourceType::TYPE_TIMER, "TYPE_TIMER");
258 
259     napi_property_descriptor exportFuncs[] = {
260         DECLARE_NAPI_PROPERTY("SourceType", obj),
261     };
262 
263     napi_define_properties(env, exports, sizeof(exportFuncs) / sizeof(*exportFuncs), exportFuncs);
264     return exports;
265 }
266 
NotificationFlagTypeInit(napi_env env,napi_value exports)267 napi_value NotificationFlagTypeInit(napi_env env, napi_value exports)
268 {
269     ANS_LOGI("%{public}s, called", __func__);
270 
271     napi_value obj = nullptr;
272     napi_create_object(env, &obj);
273 
274     SetNamedPropertyByInteger(env, obj, (int32_t)NotificationFlagStatus::TYPE_NONE, "TYPE_NONE");
275     SetNamedPropertyByInteger(env, obj, (int32_t)NotificationFlagStatus::TYPE_OPEN, "TYPE_OPEN");
276     SetNamedPropertyByInteger(env, obj, (int32_t)NotificationFlagStatus::TYPE_CLOSE, "TYPE_CLOSE");
277 
278     napi_property_descriptor exportFuncs[] = {
279         DECLARE_NAPI_PROPERTY("NotificationFlagStatus", obj),
280     };
281 
282     napi_define_properties(env, exports, sizeof(exportFuncs) / sizeof(*exportFuncs), exportFuncs);
283     return exports;
284 }
285 
ConstantInit(napi_env env,napi_value exports)286 napi_value ConstantInit(napi_env env, napi_value exports)
287 {
288     RemoveReasonInit(env, exports);
289     SlotTypeInit(env, exports);
290     SlotLevelInit(env, exports);
291     SemanticActionButtonInit(env, exports);
292     InputsSourceInit(env, exports);
293     DoNotDisturbMode(env, exports);
294     InputEditTypeInit(env, exports);
295     ContentTypeInit(env, exports);
296     SourceTypeInit(env, exports);
297     DoNotDisturbTypeInit(env, exports);
298     DeviceRemindTypeInit(env, exports);
299     NotificationFlagTypeInit(env, exports);
300     return exports;
301 }
302 }  // namespace NotificationNapi
303 }  // namespace OHOS
304