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