openharmony-ability-derive

Crates.ioopenharmony-ability-derive
lib.rsopenharmony-ability-derive
version0.2.2
created_at2025-01-24 06:15:05.383069+00
updated_at2025-08-21 02:17:36.085678+00
descriptionBinding Rust application macro on Harmony with Ability
homepage
repository
max_upload_size
id1529086
size11,307
richerfu (richerfu)

documentation

README

openharmony-ability-derive

Introduce

openharmony-ability-derive is a macro crate for the openharmony-ability project. It provides a macro for generating code to accept the OpenHarmony/HarmonyNext ability's lifecycle callbacks.

Install

cargo add openharmony-ability-derive

Mode

We support two different mode to render.

xcomponent

Using XComponent to render code that can use OpenGL or Vulkan.

Example

use openharmony_ability_derive::ability;

#[ability]
fn openharmony_app(app: OpenHarmonyApp) {
    app.run_loop(|types| match types {
        Event::Input(k) => match k {
            InputEvent::TextInputEvent(s) => {
                hilog_info!(format!("ohos-rs macro input_text: {:?}", s).as_str());
            }
            _ => {
                hilog_info!(format!("ohos-rs macro input:").as_str());
            }
        },
        Event::WindowRedraw(_) => {}
        _ => {
            hilog_info!(format!("ohos-rs macro: {:?}", types.as_str()).as_str());
        }
    });
}

webview

Using ArkWeb to render everything.

Example

use openharmony_ability_derive::ability;

#[ability(webview)]
fn openharmony_app(app: OpenHarmonyApp) {
    app.run_loop(|types| match types {
        Event::Input(k) => match k {
            InputEvent::TextInputEvent(s) => {
                hilog_info!(format!("ohos-rs macro input_text: {:?}", s).as_str());
            }
            _ => {
                hilog_info!(format!("ohos-rs macro input:").as_str());
            }
        },
        Event::WindowRedraw(_) => {}
        _ => {
            hilog_info!(format!("ohos-rs macro: {:?}", types.as_str()).as_str());
        }
    });
}

And we also support custom protocols. Just add them into ability:

use openharmony_ability_derive::ability;

#[ability(webview, protocol = "custom,hello")]
fn openharmony_app(app: OpenHarmonyApp) {
    app.run_loop(|types| match types {
        Event::Input(k) => match k {
            InputEvent::TextInputEvent(s) => {
                hilog_info!(format!("ohos-rs macro input_text: {:?}", s).as_str());
            }
            _ => {
                hilog_info!(format!("ohos-rs macro input:").as_str());
            }
        },
        Event::WindowRedraw(_) => {}
        _ => {
            hilog_info!(format!("ohos-rs macro: {:?}", types.as_str()).as_str());
        }
    });
}
Commit count: 0

cargo fmt