Skip to main content

Mountain/RPC/CocoonService/Window/
SetWebviewHtml.rs

1#![allow(non_snake_case)]
2
3//! Update a webview panel's HTML through the trait so the content is
4//! captured in `WebviewStateDTO` and re-servable on reveal/restore.
5
6use 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}