From fa2dc74d4dac83ca31a481ac4baf004e170aada8 Mon Sep 17 00:00:00 2001 From: weishaoxiong Date: Mon, 11 Jul 2022 19:42:00 +0800 Subject: [PATCH 1/3] Signed-off-by: weishaoxiong fix : merge https://gitee.com/openharmony/miscservices_wallpaper/pulls/85 --- README_ZH.md | 4 ++-- bundle.json | 2 +- interfaces/kits/napi/BUILD.gn | 4 ++-- interfaces/kits/napi/native_module.cpp | 11 +++++++---- interfaces/kits/napi/wallpaperextension/BUILD.gn | 2 +- .../wallpaperextension/wallpaper_extension_module.cpp | 4 ++-- 6 files changed, 15 insertions(+), 12 deletions(-) diff --git a/README_ZH.md b/README_ZH.md index 8a9dcd2..d8e838a 100644 --- a/README_ZH.md +++ b/README_ZH.md @@ -144,8 +144,8 @@ wallpaper.setWallpaper(pixelmap, WALLPAPER_SYSTEM).then((data) => { js 应用接口使用说明 ``` -import Extension from '@ohos.application.WallpaperExtension' -import wallPaper from '@ohos.app.wallpaperability' +import Extension from '@ohos.wallpaperextension' +import wallPaper from '@ohos.wallpaper' export default class WallpaperExtAbility extends Extension { onCreated(want) { diff --git a/bundle.json b/bundle.json index 27fddff..4f4faa4 100644 --- a/bundle.json +++ b/bundle.json @@ -51,7 +51,7 @@ "//base/miscservices/wallpaper/frameworks/kits/extension:wallpaper_extension_module", "//base/miscservices/wallpaper/interfaces/kits/napi/wallpaperextension:wallpaperextension_napi", "//base/miscservices/wallpaper/interfaces/kits/napi/wallpaper_extension_context:wallpaperextensioncontext_napi", - "//base/miscservices/wallpaper/interfaces/kits/napi:wallpaperability", + "//base/miscservices/wallpaper/interfaces/kits/napi:wallpaper", "//base/miscservices/wallpaper/utils:wallpaper_utils", "//base/miscservices/wallpaper/frameworks/innerkitsimpl/wallpaper_manager:wallpaperdefault.jpeg", "//base/miscservices/wallpaper/frameworks/innerkitsimpl/wallpaper_manager:wallpaperlockdefault.jpeg" diff --git a/interfaces/kits/napi/BUILD.gn b/interfaces/kits/napi/BUILD.gn index 478051b..304a6e4 100644 --- a/interfaces/kits/napi/BUILD.gn +++ b/interfaces/kits/napi/BUILD.gn @@ -14,7 +14,7 @@ import("//base/miscservices/wallpaper/wallpaper.gni") import("//build/ohos.gni") -ohos_shared_library("wallpaperability") { +ohos_shared_library("wallpaper") { include_dirs = [ "//foundation/arkui/napi/interfaces/kits", "//third_party/node/src", @@ -53,7 +53,7 @@ ohos_shared_library("wallpaperability") { "ipc:ipc_core", ] - relative_install_dir = "module/app" + relative_install_dir = "module" subsystem_name = "miscservices" part_name = "wallpaper_native" } diff --git a/interfaces/kits/napi/native_module.cpp b/interfaces/kits/napi/native_module.cpp index dc446f1..184507b 100644 --- a/interfaces/kits/napi/native_module.cpp +++ b/interfaces/kits/napi/native_module.cpp @@ -37,10 +37,14 @@ EXTERN_C_START static napi_value Init(napi_env env, napi_value exports) { HILOG_INFO("napi_moudule Init start..."); + napi_value WallpaperType = nullptr; napi_value wpType_system = nullptr; napi_value wpType_lockscreen = nullptr; - napi_create_int32(env, static_cast(WALLPAPER_SYSTEM), &wpType_system); - napi_create_int32(env, static_cast(WALLPAPER_LOCKSCREEN), &wpType_lockscreen); + NAPI_CALL(env, napi_create_int32(env, static_cast(WALLPAPER_SYSTEM), &wpType_system)); + NAPI_CALL(env, napi_create_int32(env, static_cast(WALLPAPER_LOCKSCREEN), &wpType_lockscreen)); + NAPI_CALL(env, napi_create_object(env, &WallpaperType)); + NAPI_CALL(env, napi_set_named_property(env, WallpaperType, "WALLPAPER_SYSTEM", wpType_system)); + NAPI_CALL(env, napi_set_named_property(env, WallpaperType, "WALLPAPER_LOCKSCREEN", wpType_lockscreen)); napi_property_descriptor desc[] = { DECLARE_NAPI_FUNCTION("getColors", NAPI_GetColors), DECLARE_NAPI_FUNCTION("getId", NAPI_GetId), @@ -54,8 +58,7 @@ static napi_value Init(napi_env env, napi_value exports) DECLARE_NAPI_FUNCTION("screenshotLiveWallpaper", NAPI_ScreenshotLiveWallpaper), DECLARE_NAPI_FUNCTION("on", NAPI_On), DECLARE_NAPI_FUNCTION("off", NAPI_Off), - DECLARE_NAPI_STATIC_PROPERTY("WALLPAPER_SYSTEM", wpType_system), - DECLARE_NAPI_STATIC_PROPERTY("WALLPAPER_LOCKSCREEN", wpType_lockscreen), + DECLARE_NAPI_STATIC_PROPERTY("WallpaperType", WallpaperType), }; NAPI_CALL(env, napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc)); diff --git a/interfaces/kits/napi/wallpaperextension/BUILD.gn b/interfaces/kits/napi/wallpaperextension/BUILD.gn index a102086..9484f9c 100644 --- a/interfaces/kits/napi/wallpaperextension/BUILD.gn +++ b/interfaces/kits/napi/wallpaperextension/BUILD.gn @@ -44,7 +44,7 @@ ohos_shared_library("wallpaperextension_napi") { external_deps = [ "napi:ace_napi" ] - relative_install_dir = "module/application" + relative_install_dir = "module" subsystem_name = "miscservices" part_name = "wallpaper_native" } diff --git a/interfaces/kits/napi/wallpaperextension/wallpaper_extension_module.cpp b/interfaces/kits/napi/wallpaperextension/wallpaper_extension_module.cpp index ec46f94..1112e05 100644 --- a/interfaces/kits/napi/wallpaperextension/wallpaper_extension_module.cpp +++ b/interfaces/kits/napi/wallpaperextension/wallpaper_extension_module.cpp @@ -25,8 +25,8 @@ void NAPI_application_WallpaperExtension_AutoRegister() { auto moduleManager = NativeModuleManager::GetInstance(); NativeModule newModuleInfo = { - .name = "application.WallpaperExtension", - .fileName = "application/libwallpaperextension_napi.so/WallpaperExtension.js", + .name = "wallpaperextension", + .fileName = "libwallpaperextension_napi.so/WallpaperExtension.js", }; moduleManager->Register(&newModuleInfo); From d6adbc4bed1adb126396edb71ff18568cbcee140 Mon Sep 17 00:00:00 2001 From: weishaoxiong Date: Tue, 12 Jul 2022 19:50:28 +0800 Subject: [PATCH 2/3] Signed-off-by: weishaoxiong fix --- .../napi/wallpaper_extension_context/BUILD.gn | 2 +- .../wallpaper_extension_context_module.cpp | 10 +++++----- .../wallpaper_extension_module.cpp | 10 +++++----- services/src/wallpaper_service.cpp | 18 ++++++++++++------ 4 files changed, 23 insertions(+), 17 deletions(-) diff --git a/interfaces/kits/napi/wallpaper_extension_context/BUILD.gn b/interfaces/kits/napi/wallpaper_extension_context/BUILD.gn index a4830ba..1881129 100644 --- a/interfaces/kits/napi/wallpaper_extension_context/BUILD.gn +++ b/interfaces/kits/napi/wallpaper_extension_context/BUILD.gn @@ -44,7 +44,7 @@ ohos_shared_library("wallpaperextensioncontext_napi") { external_deps = [ "napi:ace_napi" ] - relative_install_dir = "module/application" + relative_install_dir = "module" subsystem_name = "miscservices" part_name = "wallpaper_native" } diff --git a/interfaces/kits/napi/wallpaper_extension_context/wallpaper_extension_context_module.cpp b/interfaces/kits/napi/wallpaper_extension_context/wallpaper_extension_context_module.cpp index 11732b8..5e6c9b8 100644 --- a/interfaces/kits/napi/wallpaper_extension_context/wallpaper_extension_context_module.cpp +++ b/interfaces/kits/napi/wallpaper_extension_context/wallpaper_extension_context_module.cpp @@ -21,19 +21,19 @@ extern const char _binary_wallpaper_extension_context_abc_start[]; extern const char _binary_wallpaper_extension_context_abc_end[]; extern "C" __attribute__((constructor)) -void NAPI_application_WallpaperExtensionContext_AutoRegister() +void NAPI_WallpaperExtensionContext_AutoRegister() { auto moduleManager = NativeModuleManager::GetInstance(); NativeModule newModuleInfo = { - .name = "application.WallpaperExtensionContext", - .fileName = "application/libwallpaperextensioncontext_napi.so/WallpaperExtensionContext.js", + .name = "WallpaperExtensionContext", + .fileName = "libwallpaperextensioncontext_napi.so/wallpaper_extension_context.js", }; moduleManager->Register(&newModuleInfo); } extern "C" __attribute__((visibility("default"))) -void NAPI_application_WallpaperExtensionContext_GetJSCode(const char **buf, int *bufLen) +void NAPI_WallpaperExtensionContext_GetJSCode(const char **buf, int *bufLen) { if (buf != nullptr) { *buf = _binary_wallpaper_extension_context_js_start; @@ -46,7 +46,7 @@ void NAPI_application_WallpaperExtensionContext_GetJSCode(const char **buf, int // ability_context JS register extern "C" __attribute__((visibility("default"))) -void NAPI_application_WallpaperExtensionContext_GetABCCode(const char **buf, int *buflen) +void NAPI_WallpaperExtensionContext_GetABCCode(const char **buf, int *buflen) { if (buf != nullptr) { *buf = _binary_wallpaper_extension_context_abc_start; diff --git a/interfaces/kits/napi/wallpaperextension/wallpaper_extension_module.cpp b/interfaces/kits/napi/wallpaperextension/wallpaper_extension_module.cpp index 1112e05..3d2e7ef 100644 --- a/interfaces/kits/napi/wallpaperextension/wallpaper_extension_module.cpp +++ b/interfaces/kits/napi/wallpaperextension/wallpaper_extension_module.cpp @@ -21,19 +21,19 @@ extern const char _binary_wallpaper_extension_abc_start[]; extern const char _binary_wallpaper_extension_abc_end[]; extern "C" __attribute__((constructor)) -void NAPI_application_WallpaperExtension_AutoRegister() +void NAPI_WallpaperExtension_AutoRegister() { auto moduleManager = NativeModuleManager::GetInstance(); NativeModule newModuleInfo = { - .name = "wallpaperextension", - .fileName = "libwallpaperextension_napi.so/WallpaperExtension.js", + .name = "WallpaperExtension", + .fileName = "libwallpaperextension_napi.so/wallpaper_extension.js", }; moduleManager->Register(&newModuleInfo); } extern "C" __attribute__((visibility("default"))) -void NAPI_application_WallpaperExtension_GetJSCode(const char **buf, int *bufLen) +void NAPI_WallpaperExtension_GetJSCode(const char **buf, int *bufLen) { if (buf != nullptr) { *buf = _binary_wallpaper_extension_js_start; @@ -46,7 +46,7 @@ void NAPI_application_WallpaperExtension_GetJSCode(const char **buf, int *bufLen // wallpaper_extension JS register extern "C" __attribute__((visibility("default"))) -void NAPI_application_WallpaperExtension_GetABCCode(const char **buf, int *buflen) +void NAPI_WallpaperExtension_GetABCCode(const char **buf, int *buflen) { if (buf != nullptr) { *buf = _binary_wallpaper_extension_abc_start; diff --git a/services/src/wallpaper_service.cpp b/services/src/wallpaper_service.cpp index 9943f7b..20a3d90 100644 --- a/services/src/wallpaper_service.cpp +++ b/services/src/wallpaper_service.cpp @@ -424,14 +424,20 @@ bool WallpaperService::MakeCropWallpaper(int wallpaperType) int32_t pictrueWidth = wallpaperPixelMap->GetWidth(); int pyScrWidth = GetWallpaperMinWidth(); int pyScrHeight = GetWallpaperMinHeight(); - if (pictrueHeight > pyScrHeight || pictrueWidth > pyScrWidth) { + bool needCropHeight = false; + bool needCropWidth = false; + if (pictrueHeight > pyScrHeight) { decodeOpts.CropRect.top = (pictrueHeight - pyScrHeight)/HALF; - decodeOpts.CropRect.width = pyScrWidth; - decodeOpts.CropRect.left = (pictrueWidth - pyScrWidth)/HALF; - decodeOpts.CropRect.height = pyScrHeight; - decodeOpts.desiredSize.width = pyScrWidth; - decodeOpts.desiredSize.height = pyScrHeight; + needCropHeight = true; } + if (pictrueWidth > pyScrWidth) { + decodeOpts.CropRect.left = (pictrueWidth - pyScrWidth)/HALF; + needCropWidth = true; + } + decodeOpts.CropRect.height = needCropHeight ? pyScrHeight : pictrueHeight; + decodeOpts.desiredSize.height = decodeOpts.CropRect.height; + decodeOpts.CropRect.width = needCropWidth ? pyScrWidth : pictrueHeight; + decodeOpts.desiredSize.width = decodeOpts.CropRect.width; wallpaperPixelMap = imageSource->CreatePixelMap(decodeOpts, errorCode); if (errorCode != 0) { ret = false; From 800158932ca285b803cae37087e6d8009d6d1c18 Mon Sep 17 00:00:00 2001 From: weishaoxiong Date: Thu, 14 Jul 2022 09:22:19 +0800 Subject: [PATCH 3/3] Signed-off-by: weishaoxiong merge !118 fix load wallpaperextensioncontext filed --- frameworks/kits/extension/src/js_wallpaper_extension.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/kits/extension/src/js_wallpaper_extension.cpp b/frameworks/kits/extension/src/js_wallpaper_extension.cpp index a641613..3f505d6 100644 --- a/frameworks/kits/extension/src/js_wallpaper_extension.cpp +++ b/frameworks/kits/extension/src/js_wallpaper_extension.cpp @@ -82,7 +82,7 @@ void JsWallpaperExtension::Init(const std::shared_ptr &recor } HILOG_INFO("JsWallpaperExtension::Init CreateJsWallpaperExtensionContext."); NativeValue* contextObj = CreateJsWallpaperExtensionContext(engine, context); - auto shellContextRef = jsRuntime_.LoadSystemModule("application.WallpaperExtensionContext", &contextObj, ARGC_ONE); + auto shellContextRef = jsRuntime_.LoadSystemModule("WallpaperExtensionContext", &contextObj, ARGC_ONE); contextObj = shellContextRef->Get(); HILOG_INFO("JsWallpaperExtension::Init Bind."); context->Bind(jsRuntime_, shellContextRef.release());