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