Skip to main content

Mountain/Vine/Server/Notification/
UnregisterCommand.rs

1//! Cocoon → Mountain `unregisterCommand` notification.
2//! Paired with `registerCommand`; removes the proxied
3//! `CommandHandler` so subsequent `commands.executeCommand` no longer
4//! routes back to the extension.
5
6use serde_json::{Value, json};
7use tauri::Emitter;
8
9use crate::{Vine::Server::MountainVinegRPCService::MountainVinegRPCService, dev_log};
10
11pub async fn UnregisterCommand(Service:&MountainVinegRPCService, Parameter:&Value) {
12	let CommandId = Parameter.get("commandId").and_then(Value::as_str).unwrap_or("");
13
14	if CommandId.is_empty() {
15		return;
16	}
17
18	if let Ok(mut Registry) = Service
19		.RunTime()
20		.Environment
21		.ApplicationState
22		.Extension
23		.Registry
24		.CommandRegistry
25		.lock()
26	{
27		Registry.remove(CommandId);
28
29		dev_log!(
30			"command-register",
31			"[MountainVinegRPCService] Cocoon unregistered command: {}",
32			CommandId
33		);
34	}
35
36	// Sky's `SkyBridge.ts:852` listens on `sky://command/unregister`.
37	// Pair with `RegisterCommand` so the workbench command-service view
38	// and Mountain's registry stay in sync when an extension disposes a
39	// command (deactivate, hot-swap, etc.).
40	let _ = Service
41		.ApplicationHandle()
42		.emit("sky://command/unregister", json!({ "id": CommandId, "commandId": CommandId }));
43}