ohos: Add FFI-APIs to navigate back and forward (#33206)

To be useful it requires using the latest version of the OH demo ArkTS app,
but it is still compatible with older versions, as the newly added FFI functions
will simply be unused in such a case.

Signed-off-by: Jonathan Schwender <jonathan.schwender@huawei.com>
This commit is contained in:
Jonathan Schwender 2024-08-27 19:48:17 +08:00 committed by GitHub
parent 658df79d88
commit 2537234090
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -13,7 +13,6 @@ use std::time::Duration;
use log::{debug, error, info, warn, LevelFilter};
use napi_derive_ohos::{module_exports, napi};
use napi_ohos::bindgen_prelude::Undefined;
use napi_ohos::threadsafe_function::{
ErrorStrategy, ThreadsafeFunction, ThreadsafeFunctionCallMode,
};
@ -85,6 +84,8 @@ enum TouchEventType {
enum ServoAction {
WakeUp,
LoadUrl(String),
GoBack,
GoForward,
TouchEvent {
kind: TouchEventType,
x: f32,
@ -120,6 +121,8 @@ impl ServoAction {
let res = match self {
WakeUp => servo.perform_updates(),
LoadUrl(url) => servo.load_uri(url.as_str()),
GoBack => servo.go_back(),
GoForward => servo.go_forward(),
TouchEvent {
kind,
x,
@ -357,11 +360,21 @@ fn init(exports: JsObject, env: Env) -> napi_ohos::Result<()> {
}
#[napi(js_name = "loadURL")]
pub fn load_url(url: String) -> Undefined {
pub fn load_url(url: String) {
debug!("load url");
call(ServoAction::LoadUrl(url)).expect("Failed to load url");
}
#[napi]
pub fn go_back() {
call(ServoAction::GoBack).expect("Failed to call servo");
}
#[napi]
pub fn go_forward() {
call(ServoAction::GoForward).expect("Failed to call servo");
}
#[napi(js_name = "registerURLcallback")]
pub fn register_url_callback(cb: JsFunction) -> napi_ohos::Result<()> {
info!("register_url_callback called!");