Skip to main content

Mountain/IPC/WindServiceHandlers/Cocoon/
ExtensionHostMessage.rs

1#![allow(unused_variables, dead_code, unused_imports)]
2
3//! Wire method: `cocoon:extensionHostMessage`.
4//! Relays binary extension-host protocol messages from Wind/Sky to Cocoon via
5//! gRPC GenericNotification. Fire-and-forget - the extension host protocol is
6//! fully async; Mountain does not await a reply.
7
8use serde_json::Value;
9use tauri::AppHandle;
10
11pub async fn Fn(_ApplicationHandle:AppHandle, Arguments:Vec<Value>) -> Result<Value, String> {
12	let ByteCount = Arguments
13		.first()
14		.map(|P| P.get("data").and_then(|D| D.as_array()).map(|A| A.len()).unwrap_or(0))
15		.unwrap_or(0);
16
17	crate::dev_log!("exthost", "cocoon:extensionHostMessage bytes={}", ByteCount);
18
19	let Payload = Arguments.first().cloned().unwrap_or(Value::Null);
20
21	tokio::spawn(async move {
22		if let Err(Error) = crate::Vine::Client::SendNotification::Fn(
23			"cocoon-main".to_string(),
24			"extensionHostMessage".to_string(),
25			Payload,
26		)
27		.await
28		{
29			crate::dev_log!("exthost", "cocoon:extensionHostMessage forward failed: {}", Error);
30		}
31	});
32
33	Ok(Value::Null)
34}