Mountain/Vine/Server/Notification/WebviewLifecycle.rs
1#![allow(non_snake_case)]
2//! Cocoon → Mountain `webview.setTitle` / `webview.setIconPath` /
3//! `webview.setHtml` notifications. Shared atom because the three wire
4//! methods map to the same suffix-split pattern; keeping them in one
5//! file avoids three near-identical 5-line files while still pinning
6//! the handler to a discoverable filename.
7//!
8//! For per-extension isolation and payload inspection, split this into
9//! three atoms (`WebviewSetTitle`, `WebviewSetIconPath`, `WebviewSetHtml`)
10//! when the divergence is worth it - the dispatcher would add two more
11//! single-line arms.
12
13use serde_json::Value;
14use tauri::Emitter;
15
16use crate::{Vine::Server::MountainVinegRPCService::MountainVinegRPCService, dev_log};
17
18pub async fn WebviewLifecycle(Service:&MountainVinegRPCService, MethodName:&str, Parameter:&Value) {
19 // Suffix mapping: stock VS Code wire methods are camelCase
20 // (`webview.setHtml`, `webview.setIconPath`), but Sky's canonical
21 // channel registry (`Common/Source/IPC/SkyEvent.rs`) standardises
22 // kebab-case for set-html (`sky://webview/set-html`) since the
23 // `setWebviewHtml` typed-RPC and `Window.rs::SetHtml` request both
24 // emit kebab. Translate `setHtml` here so every producer of the
25 // "html assignment" wire shape lands on the same Sky channel; other
26 // suffixes pass through camelCase (Sky listeners use camel for
27 // `setTitle` / `setIconPath`).
28 let RawSuffix = &MethodName["webview.".len()..];
29 let Suffix = match RawSuffix {
30 "setHtml" => "set-html",
31 Other => Other,
32 };
33 let EventName = format!("sky://webview/{}", Suffix);
34 if let Err(Error) = Service.ApplicationHandle().emit(&EventName, Parameter) {
35 dev_log!("grpc", "warn: [MountainVinegRPCService] {} emit failed: {}", EventName, Error);
36 }
37}