Mountain/RPC/CocoonService/Window/
SetWebviewHtml.rs1#![allow(non_snake_case)]
2
3use serde_json::json;
7use tauri::Emitter;
8use tonic::{Response, Status};
9use CommonLibrary::Webview::WebviewProvider::WebviewProvider;
10
11use crate::{
12 RPC::CocoonService::CocoonServiceImpl,
13 Vine::Generated::{Empty, SetWebviewHtmlRequest},
14 dev_log,
15};
16
17pub async fn Fn(Service:&CocoonServiceImpl, Request:SetWebviewHtmlRequest) -> Result<Response<Empty>, Status> {
18 dev_log!(
19 "cocoon",
20 "[CocoonService] set_webview_html: handle={} ({} bytes)",
21 Request.handle,
22 Request.html.len()
23 );
24
25 if let Err(Error) = Service
26 .environment
27 .SetWebviewHTML(Request.handle.to_string(), Request.html.clone())
28 .await
29 {
30 dev_log!("cocoon", "warn: [CocoonService] set_webview_html trait failed: {}", Error);
31 let _ = Service.environment.ApplicationHandle.emit(
32 "sky://webview/set-html",
33 json!({ "handle": Request.handle, "html": Request.html }),
34 );
35 }
36
37 Ok(Response::new(Empty {}))
38}