• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 <napi/native_api.h>
17 #include <pthread.h>
18 #include <unistd.h>
19 
20 #include <string>
21 
22 #include "hilog_wrapper.h"
23 #include "napi/native_node_api.h"
24 #include "napi_wallpaper_ability.h"
25 
26 namespace OHOS {
27 namespace WallpaperNAPI {
28 enum class WallpaperType {
29     /**
30      * Indicates the home screen wallpaper.
31      */
32     WALLPAPER_SYSTEM,
33     /**
34      * Indicates the lock screen wallpaper.
35      */
36     WALLPAPER_LOCKSCREEN
37 };
38 EXTERN_C_START
Init(napi_env env,napi_value exports)39 static napi_value Init(napi_env env, napi_value exports)
40 {
41     HILOG_INFO("napi_moudule Init start...");
42     napi_value WallpaperType = nullptr;
43     napi_value wpType_system = nullptr;
44     napi_value wpType_lockscreen = nullptr;
45     NAPI_CALL(env, napi_create_int32(env, static_cast<int32_t>(WALLPAPER_SYSTEM), &wpType_system));
46     NAPI_CALL(env, napi_create_int32(env, static_cast<int32_t>(WALLPAPER_LOCKSCREEN), &wpType_lockscreen));
47     NAPI_CALL(env, napi_create_object(env, &WallpaperType));
48     NAPI_CALL(env, napi_set_named_property(env, WallpaperType, "WALLPAPER_SYSTEM", wpType_system));
49     NAPI_CALL(env, napi_set_named_property(env, WallpaperType, "WALLPAPER_LOCKSCREEN", wpType_lockscreen));
50     napi_property_descriptor desc[] = {
51         DECLARE_NAPI_FUNCTION("getColors", NAPI_GetColors),
52         DECLARE_NAPI_FUNCTION("getColorsSync", NAPI_GetColorsSync),
53         DECLARE_NAPI_FUNCTION("getId", NAPI_GetId),
54         DECLARE_NAPI_FUNCTION("getFile", NAPI_GetFile),
55         DECLARE_NAPI_FUNCTION("getMinHeight", NAPI_GetMinHeight),
56         DECLARE_NAPI_FUNCTION("getMinHeightSync", NAPI_GetMinHeightSync),
57         DECLARE_NAPI_FUNCTION("getMinWidth", NAPI_GetMinWidth),
58         DECLARE_NAPI_FUNCTION("getMinWidthSync", NAPI_GetMinWidthSync),
59         DECLARE_NAPI_FUNCTION("isChangePermitted", NAPI_IsChangePermitted),
60         DECLARE_NAPI_FUNCTION("isOperationAllowed", NAPI_IsOperationAllowed),
61         DECLARE_NAPI_FUNCTION("reset", NAPI_Reset),
62         DECLARE_NAPI_FUNCTION("restore", NAPI_Restore),
63         DECLARE_NAPI_FUNCTION("setWallpaper", NAPI_SetWallpaper),
64         DECLARE_NAPI_FUNCTION("setImage", NAPI_SetImage),
65         DECLARE_NAPI_FUNCTION("getPixelMap", NAPI_GetPixelMap),
66         DECLARE_NAPI_FUNCTION("getImage", NAPI_GetImage),
67         DECLARE_NAPI_FUNCTION("on", NAPI_On),
68         DECLARE_NAPI_FUNCTION("off", NAPI_Off),
69         DECLARE_NAPI_STATIC_PROPERTY("WallpaperType", WallpaperType),
70     };
71 
72     NAPI_CALL(env, napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc));
73     HILOG_INFO("napi_moudule Init end...");
74     return exports;
75 }
76 
77 EXTERN_C_END
78 
79 /*
80  * Module define
81  */
82 static napi_module _module = {
83     .nm_version = 1,
84     .nm_flags = 0,
85     .nm_filename = nullptr,
86     .nm_register_func = Init,
87     .nm_modname = "wallpaper",
88     .nm_priv = ((void *)0),
89     .reserved = { 0 },
90 };
91 
RegisterModule(void)92 extern "C" __attribute__((constructor)) void RegisterModule(void)
93 {
94     napi_module_register(&_module);
95 }
96 } // namespace WallpaperNAPI
97 } // namespace OHOS