Mountain/IPC/WindServiceHandlers/Extension/NotifyCocoonDeltaExtensions.rs
1#![allow(non_snake_case)]
2//! Post-install/uninstall Cocoon notification.
3//!
4//! `$deltaExtensions` adds or removes the supplied descriptors from
5//! Cocoon's extension registry and indexes `activationEvents`, but it
6//! does **not** fire those events. The workbench emits
7//! `$activateByEvent("*")` exactly once at boot; anything installed
8//! later never sees its startup events re-fired. This helper bursts the
9//! single always-satisfied activation event (`onStartupFinished`) after
10//! delta so a VSIX with that trigger activates without a reload.
11//!
12//! Fire-and-forget: missing Cocoon (`Spawn=false`) or a
13//! transient RPC failure is logged and swallowed.
14
15use serde_json::{Value, json};
16
17use crate::{Vine, dev_log};
18
19/// Cocoon sidecar identifier; matches
20/// `CocoonManagement::COCOON_SIDE_CAR_IDENTIFIER`.
21const COCOON_SIDE_CAR_IDENTIFIER:&str = "cocoon-main";
22
23/// Timeout for fire-and-forget `$deltaExtensions` notifications; long
24/// enough to survive a busy Cocoon but short enough that install
25/// feedback isn't blocked on a stalled extension host.
26const COCOON_DELTA_TIMEOUT_MS:u64 = 10_000;
27
28pub fn NotifyCocoonDeltaExtensions(ToAdd:Vec<Value>, ToRemove:Vec<Value>) {
29 tokio::spawn(async move {
30 let Parameters = json!({
31 "toAdd": ToAdd,
32 "toRemove": ToRemove,
33 });
34
35 match Vine::Client::SendRequest::Fn(
36 &COCOON_SIDE_CAR_IDENTIFIER.to_string(),
37 "$deltaExtensions".to_string(),
38 Parameters,
39 COCOON_DELTA_TIMEOUT_MS,
40 )
41 .await
42 {
43 Ok(Response) => {
44 dev_log!("extensions", "$deltaExtensions applied: {}", Response);
45 },
46 Err(Error) => {
47 dev_log!("extensions", "warn: $deltaExtensions failed (non-fatal): {}", Error);
48 // Skip the activation burst when delta itself failed.
49 return;
50 },
51 }
52
53 // Only `onStartupFinished` is fired post-delta - the one event
54 // guaranteed to be already satisfied by the time user
55 // interaction could reach the install handler (lifecycle phase
56 // Ready). Firing `"*"` would over-activate lazy extensions.
57 for Event in ["onStartupFinished"] {
58 let ActivationParameters = json!({ "activationEvent": Event });
59 match Vine::Client::SendRequest::Fn(
60 &COCOON_SIDE_CAR_IDENTIFIER.to_string(),
61 "$activateByEvent".to_string(),
62 ActivationParameters,
63 COCOON_DELTA_TIMEOUT_MS,
64 )
65 .await
66 {
67 Ok(Response) => {
68 dev_log!("extensions", "$activateByEvent({}) post-delta applied: {}", Event, Response);
69 },
70 Err(Error) => {
71 dev_log!(
72 "extensions",
73 "warn: $activateByEvent({}) post-delta failed (non-fatal): {}",
74 Event,
75 Error
76 );
77 },
78 }
79 }
80 });
81}