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,25 +13,30 @@ 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() {
Self {}
}
}
#[async_trait]
impl Handler for NeovimHandler {
type Writer = TxWrapper;
async fn handle_notify(
&self,
event_name: String,
arguments: Vec<Value>,
_neovim: Neovim<TxWrapper>,
) {
trace!("Neovim notification: {:?}", &event_name);
match event_name.as_ref() {
"redraw" => {
for events in event.arguments {
for events in arguments {
let parsed_events = parse_redraw_event(events)
.unwrap_or_explained_panic("Could not parse event from neovim");
@ -46,7 +47,7 @@ impl NeovimHandler {
}
}
"setting_changed" => {
SETTINGS.handle_changed_notification(event.arguments);
SETTINGS.handle_changed_notification(arguments);
}
#[cfg(windows)]
"neovide.register_right_click" => {
@ -61,30 +62,4 @@ impl NeovimHandler {
_ => {}
}
}
});
Self {
sender: Arc::new(Mutex::new(sender)),
}
}
}
#[async_trait]
impl Handler for NeovimHandler {
type Writer = TxWrapper;
async fn handle_notify(
&self,
event_name: String,
arguments: Vec<Value>,
_neovim: Neovim<TxWrapper>,
) {
trace!("Neovim notification: {:?}", &event_name);
let sender = self.sender.lock().await;
sender
.send(NotificationEvent {
event_name,
arguments,
})
.ok();
}
}

Loading…
Cancel
Save