• 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("getIdSync", NAPI_GetIdSync),
55         DECLARE_NAPI_FUNCTION("getFile", NAPI_GetFile),
56         DECLARE_NAPI_FUNCTION("getFileSync", NAPI_GetFileSync),
57         DECLARE_NAPI_FUNCTION("getMinHeight", NAPI_GetMinHeight),
58         DECLARE_NAPI_FUNCTION("getMinHeightSync", NAPI_GetMinHeightSync),
59         DECLARE_NAPI_FUNCTION("getMinWidth", NAPI_GetMinWidth),
60         DECLARE_NAPI_FUNCTION("getMinWidthSync", NAPI_GetMinWidthSync),
61         DECLARE_NAPI_FUNCTION("isChangePermitted", NAPI_IsChangePermitted),
62         DECLARE_NAPI_FUNCTION("isChangeAllowed", NAPI_IsChangeAllowed),
63         DECLARE_NAPI_FUNCTION("isOperationAllowed", NAPI_IsOperationAllowed),
64         DECLARE_NAPI_FUNCTION("isUserChangeAllowed", NAPI_IsUserChangeAllowed),
65         DECLARE_NAPI_FUNCTION("reset", NAPI_Reset),
66         DECLARE_NAPI_FUNCTION("restore", NAPI_Restore),
67         DECLARE_NAPI_FUNCTION("setWallpaper", NAPI_SetWallpaper),
68         DECLARE_NAPI_FUNCTION("setImage", NAPI_SetImage),
69         DECLARE_NAPI_FUNCTION("getPixelMap", NAPI_GetPixelMap),
70         DECLARE_NAPI_FUNCTION("getImage", NAPI_GetImage),
71         DECLARE_NAPI_FUNCTION("on", NAPI_On),
72         DECLARE_NAPI_FUNCTION("off", NAPI_Off),
73         DECLARE_NAPI_STATIC_PROPERTY("WallpaperType", WallpaperType),
74     };
75 
76     NAPI_CALL(env, napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc));
77     HILOG_INFO("napi_moudule Init end...");
78     return exports;
79 }
80 
81 EXTERN_C_END
82 
83 /*
84  * Module define
85  */
86 static napi_module _module = {
87     .nm_version = 1,
88     .nm_flags = 0,
89     .nm_filename = nullptr,
90     .nm_register_func = Init,
91     .nm_modname = "wallpaper",
92     .nm_priv = ((void *)0),
93     .reserved = { 0 },
94 };
95 
RegisterModule(void)96 extern "C" __attribute__((constructor)) void RegisterModule(void)
97 {
98     napi_module_register(&_module);
99 }
100 } // namespace WallpaperNAPI
101 } // namespace OHOS