mirror of
https://github.com/openharmony/windowmanager.git
synced 2026-07-19 17:08:11 -04:00
增加js接口
Signed-off-by: dubj <dubingjian@huawei.com> Change-Id: Ie4efb20b953d816d479f860d711331b89342f335
This commit is contained in:
@@ -23,6 +23,7 @@ config("libwindow_extension_private_config") {
|
||||
"../extension_connection/include/zidl",
|
||||
"../../interfaces/kits/napi/window_runtime/window_napi",
|
||||
"//foundation/aafwk/standard/frameworks/kits/ability/ability_runtime/include",
|
||||
"//foundation/aafwk/standard/interfaces/kits/napi/aafwk/inner/napi_common",
|
||||
"//foundation/aafwk/standard/interfaces/innerkits/runtime/include",
|
||||
]
|
||||
}
|
||||
@@ -50,6 +51,7 @@ ohos_shared_library("libwindow_extension") {
|
||||
public_configs = [ ":libwindow_extension_public_config" ]
|
||||
|
||||
deps = [
|
||||
"//foundation/aafwk/standard/interfaces/kits/napi/aafwk/inner/napi_common:napi_common",
|
||||
"//foundation/graphic/standard/rosen/modules/render_service_client:librender_service_client",
|
||||
"//foundation/windowmanager/interfaces/kits/napi/window_runtime:window_native_kit",
|
||||
"//foundation/windowmanager/wm:libwm",
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
|
||||
#include "js_window_extension.h"
|
||||
|
||||
#include <napi_common_want.h>
|
||||
#include <native_engine/native_reference.h>
|
||||
#include <native_engine/native_value.h>
|
||||
#include <js_extension_context.h>
|
||||
@@ -143,6 +144,19 @@ sptr<IRemoteObject> JsWindowExtension::OnConnect(const AAFwk::Want &want)
|
||||
{
|
||||
WLOGFI("called.");
|
||||
Extension::OnConnect(want);
|
||||
NativeEngine& engine = jsRuntime_.GetNativeEngine();
|
||||
std::unique_ptr<AsyncTask::CompleteCallback> complete = std::make_unique<AsyncTask::CompleteCallback>(
|
||||
[=] (NativeEngine &engine, AsyncTask &task, int32_t status) {
|
||||
NativeEngine* nativeEngine = &jsRuntime_.GetNativeEngine();
|
||||
napi_value napiWant = OHOS::AppExecFwk::WrapWant(reinterpret_cast<napi_env>(nativeEngine), want);
|
||||
NativeValue* nativeWant = reinterpret_cast<NativeValue*>(napiWant);
|
||||
NativeValue* argv[] = { nativeWant };
|
||||
CallJsMethod("onConnect", argv, ArraySize(argv));
|
||||
}
|
||||
);
|
||||
NativeReference* callback = nullptr;
|
||||
std::unique_ptr<AsyncTask::ExecuteCallback> execute = nullptr;
|
||||
AsyncTask::Schedule(engine, std::make_unique<AsyncTask>(callback, std::move(execute), std::move(complete)));
|
||||
|
||||
if (!stub_) {
|
||||
WLOGFE("stub is nullptr.");
|
||||
@@ -155,6 +169,19 @@ sptr<IRemoteObject> JsWindowExtension::OnConnect(const AAFwk::Want &want)
|
||||
void JsWindowExtension::OnDisconnect(const AAFwk::Want &want)
|
||||
{
|
||||
Extension::OnDisconnect(want);
|
||||
NativeEngine& engine = jsRuntime_.GetNativeEngine();
|
||||
std::unique_ptr<AsyncTask::CompleteCallback> complete = std::make_unique<AsyncTask::CompleteCallback>(
|
||||
[=] (NativeEngine &engine, AsyncTask &task, int32_t status) {
|
||||
NativeEngine* nativeEngine = &jsRuntime_.GetNativeEngine();
|
||||
napi_value napiWant = OHOS::AppExecFwk::WrapWant(reinterpret_cast<napi_env>(nativeEngine), want);
|
||||
NativeValue* nativeWant = reinterpret_cast<NativeValue*>(napiWant);
|
||||
NativeValue* argv[] = { nativeWant };
|
||||
CallJsMethod("onDisconnect", argv, ArraySize(argv));
|
||||
}
|
||||
);
|
||||
NativeReference* callback = nullptr;
|
||||
std::unique_ptr<AsyncTask::ExecuteCallback> execute = nullptr;
|
||||
AsyncTask::Schedule(engine, std::make_unique<AsyncTask>(callback, std::move(execute), std::move(complete)));
|
||||
WLOGFI("called.");
|
||||
}
|
||||
|
||||
|
||||
@@ -14,12 +14,16 @@
|
||||
*/
|
||||
|
||||
class WindowExtension {
|
||||
onAbilityConnected() {
|
||||
console.log('onAbilityConnected');
|
||||
onWindowReady(window) {
|
||||
console.log('WindowExtension windowReady');
|
||||
}
|
||||
|
||||
onWindowReady(window) {
|
||||
console.log('windowReady');
|
||||
onConnect(want) {
|
||||
console.log('WindowExtension onConnect, want:' + want.abilityName);
|
||||
}
|
||||
|
||||
onDisconnect(want) {
|
||||
console.log('WindowExtension onDisconnect' + want.abilityName);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user