Mountain/RPC/CocoonService/Window/
PostWebviewMessage.rs1
2use serde_json::json;
7use tauri::Emitter;
8use tonic::{Response, Status};
9
10use crate::{
11 RPC::CocoonService::CocoonServiceImpl,
12 Vine::Generated::{Empty, PostWebviewMessageRequest, post_webview_message_request},
13 dev_log,
14};
15
16pub async fn Fn(Service:&CocoonServiceImpl, Request:PostWebviewMessageRequest) -> Result<Response<Empty>, Status> {
17 dev_log!("cocoon", "[CocoonService] post_webview_message: handle={}", Request.handle);
18
19 let Payload = match &Request.message {
20 Some(post_webview_message_request::Message::StringMessage(S)) => json!(S),
21
22 Some(post_webview_message_request::Message::BytesMessage(B)) => json!(B),
23
24 None => serde_json::Value::Null,
25 };
26
27 let _ = Service.environment.ApplicationHandle.emit(
28 "sky://webview/post-message",
29 json!({ "handle": Request.handle, "message": Payload }),
30 );
31
32 Ok(Response::new(Empty {}))
33}