Skip to main content

DevelopmentNodeEnvironment_MicrosoftVSCodeDependency_22NodeVersion_Bundle_Clean_Debug_ElectronProfile_EsbuildCompiler_Mountain/IPC/WindServiceHandlers/Cocoon/
Request.rs

1#![allow(non_snake_case, unused_variables, dead_code, unused_imports)]
2
3//! Wire method: `cocoon:request`.
4//! Generic renderer→Cocoon RPC bridge for two-way wire methods that expect
5//! a reply (e.g. `webview.resolveView`). Waits up to 5 s for the gRPC
6//! handshake before dispatching; allows up to 30 s for the Cocoon reply.
7
8use serde_json::Value;
9
10pub async fn CocoonRequest(Arguments:Vec<Value>) -> Result<Value, String> {
11	crate::dev_log!("ipc", "cocoon:request method={:?}", Arguments.first());
12	let MethodOpt = Arguments.first().and_then(|V| V.as_str()).map(|S| S.to_string());
13	match MethodOpt {
14		None => Err("cocoon:request requires method string in slot 0".to_string()),
15		Some(Method) => {
16			let Payload = Arguments.get(1).cloned().unwrap_or(Value::Null);
17			// Boot-race guard: the renderer can dispatch `cocoon:request` before
18			// Cocoon's gRPC handshake completes. 5000 ms chosen because the
19			// bundled-electron boot trace shows Cocoon's `Successfully connected`
20			// lands ~620 log lines after the workbench's first request.
21			let _ = crate::Vine::Client::WaitForClientConnection::Fn("cocoon-main", 5000).await;
22			crate::Vine::Client::SendRequest::Fn("cocoon-main", Method.clone(), Payload, 30_000)
23				.await
24				.map_err(|Error| format!("cocoon:request {} failed: {:?}", Method, Error))
25		},
26	}
27}