Mountain/RPC/CocoonService/Terminal/
OpenTerminal.rs1#![allow(non_snake_case)]
2
3use serde_json::json;
8use tonic::{Response, Status};
9use CommonLibrary::Terminal::TerminalProvider::TerminalProvider;
10
11use crate::{
12 RPC::CocoonService::CocoonServiceImpl,
13 Vine::Generated::{Empty, OpenTerminalRequest},
14 dev_log,
15};
16
17pub async fn Fn(Service:&CocoonServiceImpl, Request:OpenTerminalRequest) -> Result<Response<Empty>, Status> {
18 dev_log!("cocoon", "[CocoonService] Opening terminal: {}", Request.name);
19
20 let Options = json!({
21 "name": Request.name,
22 "shellPath": if Request.shell_path.is_empty() { serde_json::Value::Null } else { json!(Request.shell_path) },
23 "shellArgs": Request.shell_args,
24 "cwd": if Request.cwd.is_empty() { serde_json::Value::Null } else { json!(Request.cwd) },
25 });
26
27 match Service.environment.CreateTerminal(Options).await {
28 Ok(Info) => {
29 dev_log!("cocoon", "[CocoonService] Terminal created: {:?}", Info);
30 Ok(Response::new(Empty {}))
31 },
32 Err(Error) => {
33 dev_log!("cocoon", "error: [CocoonService] open_terminal failed: {}", Error);
34 Err(Status::internal(format!("open_terminal: {}", Error)))
35 },
36 }
37}