Mountain/RPC/CocoonService/Terminal/
ResizeTerminal.rs1use serde_json::json;
7use tauri::Emitter;
8use tonic::{Response, Status};
9use CommonLibrary::{Environment::Requires::Requires, Terminal::TerminalProvider::TerminalProvider};
10use ::Vine::Generated::{Empty, ResizeTerminalRequest};
11
12use crate::{RPC::CocoonService::CocoonServiceImpl, dev_log};
13
14pub async fn Fn(Service:&CocoonServiceImpl, Request:ResizeTerminalRequest) -> Result<Response<Empty>, Status> {
15 let TerminalId = Request.terminal_id;
16
17 let Cols = Request.cols.max(1) as u16;
18
19 let Rows = Request.rows.max(1) as u16;
20
21 dev_log!(
22 "cocoon",
23 "[CocoonService] resize_terminal id={} cols={} rows={}",
24 TerminalId,
25 Cols,
26 Rows
27 );
28
29 let Provider:std::sync::Arc<dyn TerminalProvider> = Service.environment.Require();
31
32 if let Err(Error) = Provider.ResizeTerminal(TerminalId.into(), Cols, Rows).await {
33 dev_log!(
34 "cocoon",
35 "warn: [CocoonService] resize_terminal id={} failed: {}",
36 TerminalId,
37 Error
38 );
39 }
40
41 let _ = Service
43 .environment
44 .ApplicationHandle
45 .emit("sky://terminal/resize", json!({ "id": TerminalId, "cols": Cols, "rows": Rows }));
46
47 Ok(Response::new(Empty {}))
48}