1use crate::hotkeys::{Hotkey, HotkeyHandler};
11use crate::input::{GlobalInputEvent, GlobalInputHandler};
12use serde_json::json;
13use std::sync::{Arc, Mutex};
14
15pub type Outbox = Arc<Mutex<Vec<String>>>;
17
18pub struct PushHandler {
20 outbox: Outbox,
21}
22
23impl PushHandler {
24 pub fn new(outbox: Outbox) -> Arc<Self> {
25 Arc::new(Self { outbox })
26 }
27}
28
29impl HotkeyHandler for PushHandler {
30 fn on_hotkey(&self, id: u32, hotkey: &Hotkey) {
31 if let Ok(s) =
32 serde_json::to_string(&json!({ "cmd": "rdesktop.globalHotkey", "payload": { "id": id, "combo": hotkey.to_string() } }))
33 {
34 self.outbox.lock().unwrap().push(s);
35 }
36 }
37}
38
39impl GlobalInputHandler for PushHandler {
40 fn on_event(&self, event: GlobalInputEvent) {
41 if let Ok(s) =
42 serde_json::to_string(&json!({ "cmd": "rdesktop.globalInput", "payload": event }))
43 {
44 self.outbox.lock().unwrap().push(s);
45 }
46 }
47}