DevelopmentNodeEnvironment_MicrosoftVSCodeDependency_22NodeVersion_Bundle_Clean_Debug_ElectronProfile_EsbuildCompiler_Mountain/IPC/WindServiceHandlers/Commands/
Execute.rs1use std::sync::Arc;
6
7use serde_json::{Value, json};
8use tauri::Emitter;
9
10use crate::{RunTime::ApplicationRunTime::ApplicationRunTime, dev_log};
11
12pub async fn Fn(RunTime:Arc<ApplicationRunTime>, Arguments:Vec<Value>) -> Result<Value, String> {
13 use CommonLibrary::Command::CommandExecutor::CommandExecutor;
14
15 let CommandId = Arguments
16 .first()
17 .and_then(|V| V.as_str())
18 .ok_or_else(|| "commands:execute requires string command_id as first argument".to_string())?
19 .to_string();
20
21 let CommandArgs:Vec<Value> = Arguments.into_iter().skip(1).collect();
22
23 let Argument = CommandArgs.first().cloned().unwrap_or(Value::Null);
24
25 dev_log!("ipc", "commands:execute id={}", CommandId);
26
27 let Result = RunTime
28 .Environment
29 .ExecuteCommand(CommandId.clone(), Argument)
30 .await
31 .map_err(|Error| format!("commands:execute failed: {}", Error));
32
33 let _ = RunTime.Environment.ApplicationHandle.emit(
34 "sky://commands/executed",
35 json!({ "command": CommandId, "arguments": CommandArgs }),
36 );
37
38 let _ = crate::Vine::Client::SendNotification::Fn(
48 "cocoon-main".to_string(),
49 "$acceptCommandExecuted".to_string(),
50 json!({ "command": CommandId, "arguments": CommandArgs }),
51 )
52 .await;
53
54 Result
55}