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