Skip to main content

Mountain/IPC/WindServiceHandlers/Cocoon/
ExtensionHostMessage.rs

1//! Wire method: `cocoon:extensionHostMessage`.
2//! Relays binary extension-host protocol messages from Wind/Sky to Cocoon via
3//! gRPC GenericNotification. Fire-and-forget - the extension host protocol is
4//! fully async; Mountain does not await a reply.
5
6use serde_json::Value;
7use tauri::AppHandle;
8
9use crate::IPC::WindServiceHandlers::Utilities::JsonValueHelpers::arg_val;
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 = arg_val(&Arguments, 0);
20
21	tokio::spawn(async move {
22		if let Err(Error) =
23			::Vine::Client::SendNotification::Fn("cocoon-main".to_string(), "extensionHostMessage".to_string(), Payload)
24				.await
25		{
26			crate::dev_log!("exthost", "cocoon:extensionHostMessage forward failed: {}", Error);
27		}
28	});
29
30	Ok(Value::Null)
31}