use crate::hotkeys::{Hotkey, HotkeyHandler};
use crate::input::{GlobalInputEvent, GlobalInputHandler};
use serde_json::json;
use std::sync::{Arc, Mutex};
pub type Outbox = Arc<Mutex<Vec<String>>>;
pub struct PushHandler {
outbox: Outbox,
}
impl PushHandler {
pub fn new(outbox: Outbox) -> Arc<Self> {
Arc::new(Self { outbox })
}
}
impl HotkeyHandler for PushHandler {
fn on_hotkey(&self, id: u32, hotkey: &Hotkey) {
if let Ok(s) =
serde_json::to_string(&json!({ "cmd": "rdesktop.globalHotkey", "payload": { "id": id, "combo": hotkey.to_string() } }))
{
self.outbox.lock().unwrap().push(s);
}
}
}
impl GlobalInputHandler for PushHandler {
fn on_event(&self, event: GlobalInputEvent) {
if let Ok(s) =
serde_json::to_string(&json!({ "cmd": "rdesktop.globalInput", "payload": event }))
{
self.outbox.lock().unwrap().push(s);
}
}
}