Skip to main content

DevelopmentNodeEnvironment_MicrosoftVSCodeDependency_22NodeVersion_Bundle_Clean_Debug_ElectronProfile_EsbuildCompiler_Mountain/RPC/CocoonService/Command/
RegisterCommand.rs

1//! Wire a Cocoon-contributed command into Mountain's `CommandExecutor` as
2//! a Proxied handler that forwards back to the sidecar.
3
4use CommonLibrary::Command::CommandExecutor::CommandExecutor;
5use tonic::{Response, Status};
6
7use crate::{
8	RPC::CocoonService::CocoonServiceImpl,
9	Vine::Generated::{Empty, RegisterCommandRequest},
10	dev_log,
11};
12
13pub async fn Fn(Service:&CocoonServiceImpl, Request:RegisterCommandRequest) -> Result<Response<Empty>, Status> {
14	dev_log!(
15		"cocoon",
16		"[CocoonService] Registering command '{}' from extension '{}'",
17		Request.command_id,
18		Request.extension_id
19	);
20
21	if let Err(Error) = Service
22		.environment
23		.RegisterCommand(Request.extension_id.clone(), Request.command_id.clone())
24		.await
25	{
26		dev_log!(
27			"cocoon",
28			"warn: [CocoonService] Failed to register command '{}': {:?}",
29			Request.command_id,
30			Error
31		);
32	} else {
33		dev_log!(
34			"cocoon",
35			"[CocoonService] Command registered: id={}, title={:?}",
36			Request.command_id,
37			Request.title
38		);
39	}
40
41	Ok(Response::new(Empty {}))
42}