Skip to main content

Mountain/RPC/CocoonService/Window/
SetWebviewHtml.rs

1
2//! Update a webview panel's HTML through the trait so the content is
3//! captured in `WebviewStateDTO` and re-servable on reveal/restore.
4
5use serde_json::json;
6use tauri::Emitter;
7use tonic::{Response, Status};
8use CommonLibrary::Webview::WebviewProvider::WebviewProvider;
9
10use crate::{
11	RPC::CocoonService::CocoonServiceImpl,
12	Vine::Generated::{Empty, SetWebviewHtmlRequest},
13	dev_log,
14};
15
16pub async fn Fn(Service:&CocoonServiceImpl, Request:SetWebviewHtmlRequest) -> Result<Response<Empty>, Status> {
17	dev_log!(
18		"cocoon",
19		"[CocoonService] set_webview_html: handle={} ({} bytes)",
20		Request.handle,
21		Request.html.len()
22	);
23
24	if let Err(Error) = Service
25		.environment
26		.SetWebviewHTML(Request.handle.to_string(), Request.html.clone())
27		.await
28	{
29		dev_log!("cocoon", "warn: [CocoonService] set_webview_html trait failed: {}", Error);
30
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}