Mountain/IPC/WindServiceHandler/
Keybinding.rs1#![allow(non_snake_case)]
2
3use std::sync::Arc;
6
7use serde_json::{Value, json};
8
9use crate::RunTime::ApplicationRunTime::ApplicationRunTime;
10
11pub async fn handle_keybinding_add(Runtime:Arc<ApplicationRunTime>, Args:Vec<Value>) -> Result<Value, String> {
13 let CommandId = Args
14 .first()
15 .and_then(|V| V.as_str())
16 .ok_or("keybinding:add requires commandId".to_string())?
17 .to_owned();
18 let KeyExpression = Args
19 .get(1)
20 .and_then(|V| V.as_str())
21 .ok_or("keybinding:add requires keybinding".to_string())?
22 .to_owned();
23 let When = Args.get(2).and_then(|V| V.as_str()).map(str::to_owned);
24 Runtime
25 .Environment
26 .ApplicationState
27 .Feature
28 .Keybindings
29 .AddKeybinding(CommandId, KeyExpression, When);
30 Ok(Value::Null)
31}
32
33pub async fn handle_keybinding_remove(Runtime:Arc<ApplicationRunTime>, Args:Vec<Value>) -> Result<Value, String> {
35 let CommandId = Args
36 .first()
37 .and_then(|V| V.as_str())
38 .ok_or("keybinding:remove requires commandId".to_string())?;
39 Runtime
40 .Environment
41 .ApplicationState
42 .Feature
43 .Keybindings
44 .RemoveKeybinding(CommandId);
45 Ok(Value::Null)
46}
47
48pub async fn handle_keybinding_lookup(Runtime:Arc<ApplicationRunTime>, Args:Vec<Value>) -> Result<Value, String> {
50 let CommandId = Args
51 .first()
52 .and_then(|V| V.as_str())
53 .ok_or("keybinding:lookup requires commandId".to_string())?;
54 let Binding = Runtime
55 .Environment
56 .ApplicationState
57 .Feature
58 .Keybindings
59 .LookupKeybinding(CommandId);
60 Ok(Binding.map(|B| json!(B)).unwrap_or(Value::Null))
61}
62
63pub async fn handle_keybinding_get_all(Runtime:Arc<ApplicationRunTime>) -> Result<Value, String> {
65 let All = Runtime.Environment.ApplicationState.Feature.Keybindings.GetAllKeybindings();
66 Ok(json!(All))
67}