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