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 #include "napi/native_api.h"
16 #include <cstddef>
17 #include <cstdint>
18 #include <cstdio>
19 #define LOG_TAG "DisplayManager_NDK"
20 #include <hilog/log.h>
21 #include <window_manager/oh_display_info.h>
22 #include <window_manager/oh_display_manager.h>
23 
24 
Add(napi_env env, napi_callback_info info)25 static napi_value Add(napi_env env, napi_callback_info info)
26 {
27     size_t argc = 2;
28     napi_value args[2] = {nullptr};
29 
30     napi_get_cb_info(env, info, &argc, args , nullptr, nullptr);
31 
32     napi_valuetype valuetype0;
33     napi_typeof(env, args[0], &valuetype0);
34 
35     napi_valuetype valuetype1;
36     napi_typeof(env, args[1], &valuetype1);
37 
38     double value0;
39     napi_get_value_double(env, args[0], &value0);
40 
41     double value1;
42     napi_get_value_double(env, args[1], &value1);
43 
44     napi_value sum;
45     napi_create_double(env, value0 + value1, &sum);
46 
47     return sum;
48 }
49 
ThrowError(napi_env env, uint32_t errCode, const char* errorMessage)50 static napi_value ThrowError(napi_env env, uint32_t errCode, const char* errorMessage)
51 {
52     OH_LOG_ERROR(LOG_APP, "ThrowError=%{public}d mdErrorMessage=%{public}s.", errCode, errorMessage);
53     napi_value errorInfo = nullptr;
54     napi_create_object(env, &errorInfo);
55     if (errorInfo == nullptr) {
56         napi_value result = nullptr;
57         napi_get_undefined(env, &result);
58         return result;
59     }
60     napi_value errorCode = nullptr;
61 
62     napi_create_uint32(env, errCode, &errorCode);
63     napi_set_named_property(env, errorInfo, "code", errorCode);
64     napi_value errMsg = nullptr;
65     napi_create_string_utf8(env, errorMessage, NAPI_AUTO_LENGTH, &errMsg);
66     napi_set_named_property(env, errorInfo, "message", errMsg);
67     napi_create_error(env, errorCode, errMsg, &errorInfo);
68     napi_value error = nullptr;
69     napi_create_type_error(env, errorCode, errMsg, &error);
70 
71     return error;
72 }
73 
GetDefaultDisplayId(napi_env env, napi_callback_info info)74 static napi_value GetDefaultDisplayId(napi_env env, napi_callback_info info)
75 {
76     OH_LOG_INFO(LOG_APP, "GetDefaultDisplayId come in...");
77     uint64_t displayId;
78     OH_LOG_INFO(LOG_APP, "GetDefaultDisplayId displayId=%{public}lu ", displayId);
79     NativeDisplayManager_ErrorCode errCode = OH_NativeDisplayManager_GetDefaultDisplayId(&displayId);
80     OH_LOG_INFO(LOG_APP, "GetDefaultDisplayId displayId=%{public}lu errorCode=%{public}d.", displayId, errCode);
81     if (errCode == NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_OK) {
82         napi_value id;
83         napi_create_uint32(env, displayId, &id);
84         return id;
85     }
86     return ThrowError(env,errCode, "get default display id failed.");
87 }
88 
GetDefaultDisplayWidth(napi_env env, napi_callback_info info)89 static napi_value GetDefaultDisplayWidth(napi_env env, napi_callback_info info)
90 {
91     int32_t displayWidth;
92     NativeDisplayManager_ErrorCode errCode = OH_NativeDisplayManager_GetDefaultDisplayWidth(&displayWidth);
93     OH_LOG_INFO(LOG_APP, "GetDefaultDisplayWidth width=%{public}d errorCode=%{public}d.", displayWidth, errCode);
94     if (errCode == NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_OK) {
95         napi_value width;
96         napi_create_int32(env, displayWidth, &width);
97         return width;
98     }
99     return ThrowError(env,errCode, "get default display width failed.");
100 }
101 
GetDefaultDisplayHeight(napi_env env, napi_callback_info info)102 static napi_value GetDefaultDisplayHeight(napi_env env, napi_callback_info info)
103 {
104     int32_t displayHeight;
105     NativeDisplayManager_ErrorCode errCode = OH_NativeDisplayManager_GetDefaultDisplayHeight(&displayHeight);
106     OH_LOG_INFO(LOG_APP, "GetDefaultDisplayHeight height=%{public}d errorCode=%{public}d.", displayHeight, errCode);
107     if (errCode == NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_OK) {
108         napi_value height;
109         napi_create_int32(env, displayHeight, &height);
110         return height;
111     }
112     return ThrowError(env,errCode, "get default display height failed.");
113 }
114 
GetDefaultDisplayRotation(napi_env env, napi_callback_info info)115 static napi_value GetDefaultDisplayRotation(napi_env env, napi_callback_info info)
116 {
117     NativeDisplayManager_Rotation displayRotation;
118     NativeDisplayManager_ErrorCode errCode = OH_NativeDisplayManager_GetDefaultDisplayRotation(&displayRotation);
119     if (errCode == NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_OK) {
120         napi_value rotation;
121         napi_create_int32(env, displayRotation, &rotation);
122         return rotation;
123     } else {
124         napi_value errorCode;
125         napi_create_int32(env, errCode, &errorCode);
126         return errorCode;
127     }
128 }
129 
GetDefaultDisplayOrientation(napi_env env, napi_callback_info info)130 static napi_value GetDefaultDisplayOrientation(napi_env env, napi_callback_info info)
131 {
132     NativeDisplayManager_Orientation displayOrientation;
133     NativeDisplayManager_ErrorCode errCode = OH_NativeDisplayManager_GetDefaultDisplayOrientation(&displayOrientation);
134     OH_LOG_INFO(LOG_APP, "GetDefaultDisplayOrientation orientation=%{public}d errorCode=%{public}d.",
135         displayOrientation, errCode);
136     if (errCode == NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_OK) {
137         napi_value orientation;
138         napi_create_int32(env, displayOrientation, &orientation);
139         return orientation;
140     }
141     return ThrowError(env,errCode, "get default display orientation failed.");
142 }
143 
GetDefaultDisplayVirtualPixelRatio(napi_env env, napi_callback_info info)144 static napi_value GetDefaultDisplayVirtualPixelRatio(napi_env env, napi_callback_info info)
145 {
146     float dmVirtualPixels;
147     NativeDisplayManager_ErrorCode errCode = OH_NativeDisplayManager_GetDefaultDisplayVirtualPixelRatio(&dmVirtualPixels);
148     OH_LOG_INFO(LOG_APP, "GetDefaultDisplayVirtualPixelRatio dmVirtualPixels=%{public}f errorCode=%{public}d.",
149         dmVirtualPixels, errCode);
150     if (errCode == NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_OK) {
151         napi_value virtualPixels;
152         napi_create_int32(env, dmVirtualPixels, &virtualPixels);
153         return virtualPixels;
154     }
155     return ThrowError(env,errCode, "get default display virtual pixel failed.");
156 }
157 
GetDefaultDisplayRefreshRate(napi_env env, napi_callback_info info)158 static napi_value GetDefaultDisplayRefreshRate(napi_env env, napi_callback_info info)
159 {
160     uint32_t dmRefreshRate;
161     NativeDisplayManager_ErrorCode errCode = OH_NativeDisplayManager_GetDefaultDisplayRefreshRate(&dmRefreshRate);
162     OH_LOG_INFO(LOG_APP, "GetDefaultDisplayRefreshRate dmRefreshRate=%{public}d errorCode=%{public}d.", dmRefreshRate,
163         errCode);
164     if (errCode == NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_OK) {
165         napi_value refreshRate;
166         napi_create_int32(env, dmRefreshRate, &refreshRate);
167         return refreshRate;
168     }
169     return ThrowError(env,errCode, "get default display refresh rate failed.");
170 }
171 
GetDefaultDisplayDensityDpi(napi_env env, napi_callback_info info)172 static napi_value GetDefaultDisplayDensityDpi(napi_env env, napi_callback_info info)
173 {
174     int32_t dmDensityDpi;
175     NativeDisplayManager_ErrorCode errCode = OH_NativeDisplayManager_GetDefaultDisplayDensityDpi(&dmDensityDpi);
176     OH_LOG_INFO(LOG_APP, "GetDefaultDisplayDensityDpi dmDensityDpi=%{public}d errorCode=%{public}d.", dmDensityDpi,
177         errCode);
178     if (errCode == NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_OK) {
179         napi_value densityDpi;
180         napi_create_int32(env, dmDensityDpi, &densityDpi);
181         return densityDpi;
182     }
183     return ThrowError(env,errCode, "get default display density dpi failed.");
184 }
185 
GetDefaultDisplayDensityPixels(napi_env env, napi_callback_info info)186 static napi_value GetDefaultDisplayDensityPixels(napi_env env, napi_callback_info info)
187 {
188     float dmDensityPixels;
189     NativeDisplayManager_ErrorCode errCode = OH_NativeDisplayManager_GetDefaultDisplayDensityPixels(&dmDensityPixels);
190     OH_LOG_INFO(LOG_APP, "GetDefaultDisplayDensityPixels dmDensityPixels=%{public}f errorCode=%{public}d.",
191         dmDensityPixels, errCode);
192     if (errCode == NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_OK) {
193         napi_value densityPixels;
194         napi_create_int32(env, dmDensityPixels, &densityPixels);
195         return densityPixels;
196     }
197     return ThrowError(env,errCode, "get default display density pixels failed.");
198 }
199 
GetDefaultDisplayScaledDensity(napi_env env, napi_callback_info info)200 static napi_value GetDefaultDisplayScaledDensity(napi_env env, napi_callback_info info)
201 {
202     float dmScaledDensity;
203     NativeDisplayManager_ErrorCode errCode = OH_NativeDisplayManager_GetDefaultDisplayScaledDensity(&dmScaledDensity);
204     OH_LOG_INFO(LOG_APP, "GetDefaultDisplayScaledDensity dmDensityPixels=%{public}f errorCode=%{public}d.",
205         dmScaledDensity, errCode);
206     if (errCode == NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_OK) {
207         napi_value scaledDensity;
208         napi_create_int32(env, dmScaledDensity, &scaledDensity);
209         return scaledDensity;
210     }
211     return ThrowError(env,errCode, "get default display density pixels failed.");
212 }
213 
GetDefaultDisplayDensityXdpi(napi_env env, napi_callback_info info)214 static napi_value GetDefaultDisplayDensityXdpi(napi_env env, napi_callback_info info)
215 {
216     float dmxDpi;
217     NativeDisplayManager_ErrorCode errCode = OH_NativeDisplayManager_GetDefaultDisplayDensityXdpi(&dmxDpi);
218     OH_LOG_INFO(LOG_APP, "GetDefaultDisplayDensityXdpi dmxDpi =%{public}f errorCode=%{public}d.", dmxDpi, errCode);
219     if (errCode == NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_OK) {
220         napi_value xDpi;
221         napi_create_int32(env, dmxDpi, &xDpi);
222         return xDpi;
223     }
224     return ThrowError(env,errCode, "get default display xDPI failed.");
225 }
226 
GetDefaultDisplayDensityYdpi(napi_env env, napi_callback_info info)227 static napi_value GetDefaultDisplayDensityYdpi(napi_env env, napi_callback_info info)
228 {
229     float dmyDpi;
230     NativeDisplayManager_ErrorCode errCode = OH_NativeDisplayManager_GetDefaultDisplayDensityYdpi(&dmyDpi);
231     OH_LOG_INFO(LOG_APP, "GetDefaultDisplayDensityYdpi dmyDpi =%{public}f errorCode=%{public}d.", dmyDpi, errCode);
232     if (errCode == NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_OK) {
233         napi_value xDpi;
234         napi_create_int32(env, dmyDpi, &xDpi);
235         return xDpi;
236     }
237     return ThrowError(env,errCode, "get default display xDPI failed.");
238 }
239 
CreateDefaultDisplayCutoutInfo(napi_env env, napi_callback_info info)240 static napi_value CreateDefaultDisplayCutoutInfo(napi_env env, napi_callback_info info)
241 {
242     NativeDisplayManager_CutoutInfo *cutOutInfo = NULL;
243     NativeDisplayManager_ErrorCode errCode = OH_NativeDisplayManager_CreateDefaultDisplayCutoutInfo(&cutOutInfo);
244     OH_LOG_INFO(LOG_APP, "GetDefaultCutoutInfo errCode=%{public}d", errCode);
245     if (errCode == NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_OK) {
246         if (cutOutInfo != NULL && cutOutInfo->boundingRectsLength != 0) {
247             OH_LOG_INFO(LOG_APP, "GetDefaultCutoutInfo cutOutInfo length=%{public}d", cutOutInfo->boundingRectsLength);
248             for (int i = 0; i < cutOutInfo->boundingRectsLength; i++) {
249                 OH_LOG_INFO(LOG_APP, "cutOutInfo[%{public}d]=[%{public}d %{public}d %{public}d %{public}d]",
250                     i, cutOutInfo->boundingRects[i].left, cutOutInfo->boundingRects[i].top,
251                     cutOutInfo->boundingRects[i].width, cutOutInfo->boundingRects[i].height);
252             }
253             OH_LOG_INFO(LOG_APP, "cutOutInfo waterfall left rect=[%{public}d %{public}d %{public}d %{public}d]",
254             cutOutInfo->waterfallDisplayAreaRects.left.left, cutOutInfo->waterfallDisplayAreaRects.left.top,
255             cutOutInfo->waterfallDisplayAreaRects.left.left, cutOutInfo->waterfallDisplayAreaRects.left.left);
256             OH_LOG_INFO(LOG_APP, "cutOutInfo waterfall top rect=[%{public}d %{public}d %{public}d %{public}d]",
257             cutOutInfo->waterfallDisplayAreaRects.top.left, cutOutInfo->waterfallDisplayAreaRects.top.top,
258             cutOutInfo->waterfallDisplayAreaRects.top.left, cutOutInfo->waterfallDisplayAreaRects.top.left);
259             OH_LOG_INFO(LOG_APP, "cutOutInfo waterfall right rect=[%{public}d %{public}d %{public}d %{public}d]",
260             cutOutInfo->waterfallDisplayAreaRects.right.left, cutOutInfo->waterfallDisplayAreaRects.right.top,
261             cutOutInfo->waterfallDisplayAreaRects.right.left, cutOutInfo->waterfallDisplayAreaRects.right.left);
262             OH_LOG_INFO(LOG_APP, "cutOutInfo waterfall bottom rect=[%{public}d %{public}d %{public}d %{public}d]",
263             cutOutInfo->waterfallDisplayAreaRects.bottom.left, cutOutInfo->waterfallDisplayAreaRects.bottom.top,
264             cutOutInfo->waterfallDisplayAreaRects.bottom.left, cutOutInfo->waterfallDisplayAreaRects.bottom.left);
265         }
266         napi_value boundingRectsLength;
267         napi_create_int32(env, cutOutInfo->boundingRectsLength, &boundingRectsLength);
268         OH_NativeDisplayManager_DestroyDefaultDisplayCutoutInfo(cutOutInfo);
269         return boundingRectsLength;
270     } else {
271         napi_value errorCode;
272         napi_create_int32(env, errCode, &errorCode);
273         return errorCode;
274     }
275 }
276 
IsFoldable(napi_env env, napi_callback_info info)277 static napi_value IsFoldable(napi_env env, napi_callback_info info)
278 {
279     bool isFoldDevice = OH_NativeDisplayManager_IsFoldable();
280     OH_LOG_INFO(LOG_APP, "IsFoldable isFoldDevice =%{public}d.", isFoldDevice);
281     napi_value isFold;
282     napi_get_boolean(env, isFoldDevice, &isFold);
283     return isFold;
284 }
285 
GetFoldDisplayMode(napi_env env, napi_callback_info info)286 static napi_value GetFoldDisplayMode(napi_env env, napi_callback_info info)
287 {
288     NativeDisplayManager_FoldDisplayMode displayMode;
289     NativeDisplayManager_ErrorCode errCode = OH_NativeDisplayManager_GetFoldDisplayMode(&displayMode);
290     OH_LOG_INFO(LOG_APP, "GetFoldDisplayMode displayMode =%{public}d errorCode=%{public}d.", displayMode, errCode);
291     if (errCode == NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_OK) {
292         napi_value currentMode;
293         napi_create_int32(env, displayMode, &currentMode);
294         return currentMode;
295     } else {
296         napi_value errorCode;
297         napi_create_int32(env, errCode, &errorCode);
298         return errorCode;
299     }
300 }
301 
DisplayChangeCallback(uint64_t displayId)302 void DisplayChangeCallback(uint64_t displayId)
303 {
304     OH_LOG_INFO(LOG_APP, "DisplayChangeCallback displayId=%{public}lu.", displayId);
305 }
306 
RegisterDisplayChangeListener(napi_env env, napi_callback_info info)307 static napi_value RegisterDisplayChangeListener(napi_env env, napi_callback_info info)
308 {
309     uint32_t listenerIndex;
310     NativeDisplayManager_ErrorCode errCode = OH_NativeDisplayManager_RegisterDisplayChangeListener(
311         DisplayChangeCallback, &listenerIndex);
312     OH_LOG_INFO(LOG_APP, "RegisterDisplayChangeListener listenerIndex =%{public}d errCode=%{public}d.",
313         listenerIndex, errCode);
314     if (errCode == NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_OK) {
315         napi_value registerIndex;
316         napi_create_int32(env, listenerIndex, &registerIndex);
317         return registerIndex;
318     } else {
319         napi_value errorCode;
320         napi_create_int32(env, errCode, &errorCode);
321         return errorCode;
322     }
323 }
324 
UnregisterDisplayChangeListener(napi_env env, napi_callback_info info)325 static napi_value UnregisterDisplayChangeListener(napi_env env, napi_callback_info info)
326 {
327     size_t argc = 1;
328     napi_value args[1] = { nullptr };
329 
330     uint32_t listenerIndex;
331     napi_get_cb_info(env, info, &argc, args , nullptr, nullptr);
332     napi_get_value_uint32(env, args[0], &listenerIndex);
333     OH_LOG_INFO(LOG_APP, "UnregisterDisplayChangeListener listenerIndex =%{public}d.", listenerIndex);
334     NativeDisplayManager_ErrorCode errCode = OH_NativeDisplayManager_UnregisterDisplayChangeListener(listenerIndex);
335     OH_LOG_INFO(LOG_APP, "UnregisterDisplayChangeListener errCode=%{public}d.", errCode);
336     napi_value errorCode;
337     napi_create_int32(env, errCode, &errorCode);
338     return errorCode;
339 }
340 
FoldDisplayModeChangeCallback(NativeDisplayManager_FoldDisplayMode displayMode)341 void FoldDisplayModeChangeCallback(NativeDisplayManager_FoldDisplayMode displayMode)
342 {
343     OH_LOG_INFO(LOG_APP, "displayMode=%{public}d.", displayMode);
344 }
345 
RegisterFoldDisplayModeChangeListener(napi_env env, napi_callback_info info)346 static napi_value RegisterFoldDisplayModeChangeListener(napi_env env, napi_callback_info info)
347 {
348     uint32_t listenerIndex = 0;
349     NativeDisplayManager_ErrorCode errCode = OH_NativeDisplayManager_RegisterFoldDisplayModeChangeListener(
350         FoldDisplayModeChangeCallback, &listenerIndex);
351     OH_LOG_INFO(LOG_APP, "listenerIndex =%{public}d errCode=%{public}d.",
352         listenerIndex, errCode);
353     if (errCode == NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_OK) {
354         napi_value registerIndex;
355         napi_create_int32(env, listenerIndex, &registerIndex);
356         return registerIndex;
357     } else {
358         napi_value errorCode;
359         napi_create_int32(env, errCode, &errorCode);
360         return errorCode;
361     }
362 }
363 
UnregisterFoldDisplayModeChangeListener(napi_env env, napi_callback_info info)364 static napi_value UnregisterFoldDisplayModeChangeListener(napi_env env, napi_callback_info info)
365 {
366     size_t argc = 1;
367     napi_value args[1] = { nullptr };
368     uint32_t listenerIndex;
369     napi_get_cb_info(env, info, &argc, args , nullptr, nullptr);
370     napi_get_value_uint32(env, args[0], &listenerIndex);
371     OH_LOG_INFO(LOG_APP, "listenerIndex =%{public}d.", listenerIndex);
372     NativeDisplayManager_ErrorCode errCode = OH_NativeDisplayManager_UnregisterFoldDisplayModeChangeListener(listenerIndex);
373     OH_LOG_INFO(LOG_APP, "errorCode=%{public}d", errCode);
374     napi_value errorCode;
375     napi_create_int32(env, errCode, &errorCode);
376     return errorCode;
377 }
378 
379 EXTERN_C_START
Init(napi_env env, napi_value exports)380 static napi_value Init(napi_env env, napi_value exports)
381 {
382     napi_property_descriptor desc[] = {
383         { "add", nullptr, Add, nullptr, nullptr, nullptr, napi_default, nullptr },
384         { "getId", nullptr, GetDefaultDisplayId, nullptr, nullptr, nullptr, napi_default, nullptr },
385         { "getWidth", nullptr, GetDefaultDisplayWidth, nullptr, nullptr, nullptr, napi_default, nullptr },
386         { "getHeight", nullptr, GetDefaultDisplayHeight, nullptr, nullptr, nullptr, napi_default, nullptr },
387         { "getRotation", nullptr, GetDefaultDisplayRotation, nullptr, nullptr, nullptr, napi_default, nullptr },
388         { "getOrientation", nullptr, GetDefaultDisplayOrientation, nullptr, nullptr, nullptr, napi_default, nullptr },
389         { "getVirtualPixelRatio", nullptr, GetDefaultDisplayVirtualPixelRatio, nullptr, nullptr, nullptr,
390             napi_default, nullptr },
391         { "getRefreshRate", nullptr, GetDefaultDisplayRefreshRate, nullptr, nullptr, nullptr, napi_default, nullptr },
392         { "getDensityDpi", nullptr, GetDefaultDisplayDensityDpi, nullptr, nullptr, nullptr, napi_default, nullptr },
393         { "getDensityPixels", nullptr, GetDefaultDisplayDensityPixels, nullptr, nullptr, nullptr,
394             napi_default, nullptr },
395         { "getScaledDensity", nullptr, GetDefaultDisplayScaledDensity, nullptr, nullptr, nullptr,
396             napi_default, nullptr },
397         { "getDensityXdpi", nullptr, GetDefaultDisplayDensityXdpi, nullptr, nullptr, nullptr, napi_default, nullptr },
398         { "getDensityYdpi", nullptr, GetDefaultDisplayDensityYdpi, nullptr, nullptr, nullptr, napi_default, nullptr },
399         { "getCutoutInfo", nullptr, CreateDefaultDisplayCutoutInfo, nullptr, nullptr, nullptr, napi_default, nullptr },
400         { "checkIsFoldDevice", nullptr, IsFoldable, nullptr, nullptr, nullptr, napi_default, nullptr },
401         { "getDisplayMode", nullptr, GetFoldDisplayMode, nullptr, nullptr, nullptr, napi_default, nullptr },
402         { "registerDisplayChange", nullptr, RegisterDisplayChangeListener, nullptr, nullptr, nullptr,
403             napi_default, nullptr },
404         { "unregisterDisplayChange", nullptr, UnregisterDisplayChangeListener, nullptr, nullptr, nullptr,
405             napi_default, nullptr },
406         { "registerFoldDisplayModeChange", nullptr, RegisterFoldDisplayModeChangeListener, nullptr, nullptr, nullptr,
407             napi_default, nullptr },
408         { "unregisterFoldDisplayModeChange", nullptr, UnregisterFoldDisplayModeChangeListener, nullptr, nullptr,
409             nullptr, napi_default, nullptr },
410     };
411     napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc);
412     return exports;
413 }
414 EXTERN_C_END
415 
416 static napi_module demoModule = {
417     .nm_version = 1,
418     .nm_flags = 0,
419     .nm_filename = nullptr,
420     .nm_register_func = Init,
421     .nm_modname = "entry",
422     .nm_priv = ((void*)0),
423     .reserved = { 0 },
424 };
425 
RegisterEntryModule(void)426 extern "C" __attribute__((constructor)) void RegisterEntryModule(void)
427 {
428     napi_module_register(&demoModule);
429 }
430