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