Skip to main content

Mountain/IPC/WindServiceHandlers/Commands/
Execute.rs

1#![allow(unused_variables, dead_code, unused_imports)]
2
3//! Wire method: `commands:execute`.
4//! Dispatches to Mountain's CommandExecutor and emits
5//! `sky://commands/executed` for `vscode.commands.onDidExecuteCommand`.
6
7use std::sync::Arc;
8
9use serde_json::{Value, json};
10use tauri::Emitter;
11
12use crate::{RunTime::ApplicationRunTime::ApplicationRunTime, dev_log};
13
14pub async fn Fn(RunTime:Arc<ApplicationRunTime>, Arguments:Vec<Value>) -> Result<Value, String> {
15	use CommonLibrary::Command::CommandExecutor::CommandExecutor;
16
17	let CommandId = Arguments
18		.first()
19		.and_then(|V| V.as_str())
20		.ok_or_else(|| "commands:execute requires string command_id as first argument".to_string())?
21		.to_string();
22
23	let CommandArgs:Vec<Value> = Arguments.into_iter().skip(1).collect();
24
25	let Argument = CommandArgs.first().cloned().unwrap_or(Value::Null);
26
27	dev_log!("ipc", "commands:execute id={}", CommandId);
28
29	let Result = RunTime
30		.Environment
31		.ExecuteCommand(CommandId.clone(), Argument)
32		.await
33		.map_err(|Error| format!("commands:execute failed: {}", Error));
34
35	let _ = RunTime.Environment.ApplicationHandle.emit(
36		"sky://commands/executed",
37		json!({ "command": CommandId, "arguments": CommandArgs }),
38	);
39
40	Result
41}