don't setup separate thread

macos-click-through
Keith Simmons 3 years ago
parent b83003a8ec
commit 616ffe15ba

@ -1,11 +1,7 @@
use async_trait::async_trait;
use futures::lock::Mutex;
use log::trace;
use nvim_rs::{Handler, Neovim};
use rmpv::Value;
use std::sync::mpsc::{channel, Receiver, Sender};
use std::sync::Arc;
use std::thread;
#[cfg(windows)]
use crate::bridge::ui_commands::{ParallelCommand, UiCommand};
@ -17,54 +13,12 @@ use crate::{
settings::SETTINGS,
};
struct NotificationEvent {
event_name: String,
arguments: Vec<Value>,
}
#[derive(Clone)]
pub struct NeovimHandler {
sender: Arc<Mutex<Sender<NotificationEvent>>>,
}
pub struct NeovimHandler {}
impl NeovimHandler {
pub fn new() -> Self {
let (sender, receiver): (Sender<NotificationEvent>, Receiver<NotificationEvent>) =
channel();
thread::spawn(|| {
for event in receiver {
match event.event_name.as_ref() {
"redraw" => {
for events in event.arguments {
let parsed_events = parse_redraw_event(events)
.unwrap_or_explained_panic("Could not parse event from neovim");
for parsed_event in parsed_events {
EVENT_AGGREGATOR
.send(EditorCommand::NeovimRedrawEvent(parsed_event));
}
}
}
"setting_changed" => {
SETTINGS.handle_changed_notification(event.arguments);
}
#[cfg(windows)]
"neovide.register_right_click" => {
EVENT_AGGREGATOR
.send(UiCommand::Parallel(ParallelCommand::RegisterRightClick));
}
#[cfg(windows)]
"neovide.unregister_right_click" => {
EVENT_AGGREGATOR
.send(UiCommand::Parallel(ParallelCommand::UnregisterRightClick));
}
_ => {}
}
}
});
Self {
sender: Arc::new(Mutex::new(sender)),
}
Self {}
}
}
@ -79,12 +33,33 @@ impl Handler for NeovimHandler {
_neovim: Neovim<TxWrapper>,
) {
trace!("Neovim notification: {:?}", &event_name);
let sender = self.sender.lock().await;
sender
.send(NotificationEvent {
event_name,
arguments,
})
.ok();
match event_name.as_ref() {
"redraw" => {
for events in arguments {
let parsed_events = parse_redraw_event(events)
.unwrap_or_explained_panic("Could not parse event from neovim");
for parsed_event in parsed_events {
EVENT_AGGREGATOR
.send(EditorCommand::NeovimRedrawEvent(parsed_event));
}
}
}
"setting_changed" => {
SETTINGS.handle_changed_notification(arguments);
}
#[cfg(windows)]
"neovide.register_right_click" => {
EVENT_AGGREGATOR
.send(UiCommand::Parallel(ParallelCommand::RegisterRightClick));
}
#[cfg(windows)]
"neovide.unregister_right_click" => {
EVENT_AGGREGATOR
.send(UiCommand::Parallel(ParallelCommand::UnregisterRightClick));
}
_ => {}
}
}
}

Loading…
Cancel
Save