Skip to main content

Mountain/Vine/Server/Notification/
UnregisterCommand.rs

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