pub trait HostExtension:
Send
+ Sync
+ 'static {
// Required methods
fn namespace(&self) -> &str;
fn channel(&self) -> &str;
fn inject_script(&self) -> &str;
fn handle_message(&self, method: &str, params: &str) -> Option<String>;
// Provided method
fn drain_events(&self) -> Vec<HostPushEvent> { ... }
}Expand description
A host extension contributes a JS injection script and a message handler.
Extensions register as window.host.ext.<namespace> in the SPA WebView.
Each extension gets its own WKScriptMessageHandler channel, its own
pending-promise map, and its own resolve/push callbacks — fully independent
of the core window.host bridge.
Required Methods§
Sourcefn namespace(&self) -> &str
fn namespace(&self) -> &str
Sub-namespace under window.host.ext.* (e.g. “data” → window.host.ext.data)
Sourcefn inject_script(&self) -> &str
fn inject_script(&self) -> &str
JavaScript injected after HOST_API_SCRIPT. Must:
- Define its own
_callfunction using its own message handler channel - Define
window.__host{Name}Resolvefor response resolution - Define
window.__host{Name}Pushfor push events - Set
window.host.ext.<namespace> = Object.freeze({...})
Provided Methods§
Sourcefn drain_events(&self) -> Vec<HostPushEvent>
fn drain_events(&self) -> Vec<HostPushEvent>
Drain queued push events destined for window.host.on(...) listeners.
The returned payload is the canonical JSON string for the event’s shared Rust/TypeScript payload shape.