Skip to main content

DevelopmentNodeEnvironment_MicrosoftVSCodeDependency_22NodeVersion_Bundle_Clean_Debug_ElectronProfile_EsbuildCompiler_Mountain/IPC/WindServiceHandlers/Cocoon/
Request.rs

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