DevelopmentNodeEnvironment_MicrosoftVSCodeDependency_22NodeVersion_Bundle_Clean_Debug_ElectronProfile_EsbuildCompiler_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};
9use tauri::Emitter;
10
11use crate::{RunTime::ApplicationRunTime::ApplicationRunTime, dev_log};
12
13pub async fn CommandsExecute(RunTime:Arc<ApplicationRunTime>, Arguments:Vec<Value>) -> Result<Value, String> {
18 let CommandId = Arguments
19 .first()
20 .and_then(|V| V.as_str())
21 .ok_or_else(|| "commands:execute requires string command_id as first argument".to_string())?
22 .to_string();
23
24 let CommandArgs:Vec<Value> = Arguments.into_iter().skip(1).collect();
25
26 let Argument = CommandArgs.first().cloned().unwrap_or(Value::Null);
27
28 dev_log!("ipc", "commands:execute id={}", CommandId);
29
30 let Result = RunTime
31 .Environment
32 .ExecuteCommand(CommandId.clone(), Argument)
33 .await
34 .map_err(|Error| format!("commands:execute failed: {}", Error));
35
36 let _ = RunTime.Environment.ApplicationHandle.emit(
39 "sky://commands/executed",
40 json!({ "command": CommandId, "arguments": CommandArgs }),
41 );
42
43 Result
44}
45
46pub async fn CommandsGetAll(RunTime:Arc<ApplicationRunTime>) -> Result<Value, String> {
48 let Commands = RunTime
49 .Environment
50 .GetAllCommands()
51 .await
52 .map_err(|Error| format!("commands:getAll failed: {}", Error))?;
53
54 Ok(json!(Commands))
55}