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 if CommandId.is_empty() {
15 return;
16 }
17 if let Ok(mut Registry) = Service
18 .RunTime()
19 .Environment
20 .ApplicationState
21 .Extension
22 .Registry
23 .CommandRegistry
24 .lock()
25 {
26 Registry.remove(CommandId);
27 dev_log!(
28 "command-register",
29 "[MountainVinegRPCService] Cocoon unregistered command: {}",
30 CommandId
31 );
32 }
33 // Sky's `SkyBridge.ts:852` listens on `sky://command/unregister`.
34 // Pair with `RegisterCommand` so the workbench command-service view
35 // and Mountain's registry stay in sync when an extension disposes a
36 // command (deactivate, hot-swap, etc.).
37 let _ = Service
38 .ApplicationHandle()
39 .emit("sky://command/unregister", json!({ "id": CommandId, "commandId": CommandId }));
40}