Mountain/IPC/WindServiceHandlers/
Commands.rs1#![allow(non_snake_case, unused_variables, dead_code, unused_imports)]
2
3use std::sync::Arc;
6
7use CommonLibrary::Command::CommandExecutor::CommandExecutor;
8use serde_json::{Value, json};
9
10use crate::{RunTime::ApplicationRunTime::ApplicationRunTime, dev_log};
11
12pub async fn CommandsExecute(RunTime:Arc<ApplicationRunTime>, Arguments:Vec<Value>) -> Result<Value, String> {
14 let CommandId = Arguments
15 .first()
16 .and_then(|V| V.as_str())
17 .ok_or_else(|| "commands:execute requires string command_id as first argument".to_string())?
18 .to_string();
19
20 let Argument = Arguments.get(1).cloned().unwrap_or(Value::Null);
21
22 dev_log!("ipc", "commands:execute id={}", CommandId);
23
24 RunTime
25 .Environment
26 .ExecuteCommand(CommandId, Argument)
27 .await
28 .map_err(|Error| format!("commands:execute failed: {}", Error))
29}
30
31pub async fn CommandsGetAll(RunTime:Arc<ApplicationRunTime>) -> Result<Value, String> {
33 let Commands = RunTime
34 .Environment
35 .GetAllCommands()
36 .await
37 .map_err(|Error| format!("commands:getAll failed: {}", Error))?;
38
39 Ok(json!(Commands))
40}