Skip to content

Commit

Permalink
Wrap the proxy inside the Neovim handler with an Arc and Mutex
Browse files Browse the repository at this point in the history
The handler need to be send + sync + clone, and that's not the case on
all platforms.
  • Loading branch information
fredizzimo committed Dec 4, 2023
1 parent 9fdb60d commit 4943e5d
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/bridge/handler.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::sync::Arc;
use std::sync::Mutex;
use async_trait::async_trait;
use log::trace;
use nvim_rs::{Handler, Neovim};
Expand All @@ -19,12 +21,13 @@ use crate::{

#[derive(Clone)]
pub struct NeovimHandler {
proxy: EventLoopProxy<UserEvent>,
// The EventLoopProxy is not sync on all platforms, so wrap it in mutex
proxy: Arc<Mutex<EventLoopProxy<UserEvent>>>,
}

impl NeovimHandler {
pub fn new(proxy: EventLoopProxy<UserEvent>) -> Self {
Self { proxy }
Self { proxy: Arc::new(Mutex::new(proxy)) }
}
}

Expand Down Expand Up @@ -102,7 +105,7 @@ impl Handler for NeovimHandler {
}
"neovide.focus_window" => {
let _ = self
.proxy
.proxy.lock().unwrap()
.send_event(UserEvent::WindowCommand(WindowCommand::FocusWindow));
}
_ => {}
Expand Down

0 comments on commit 4943e5d

Please sign in to comment.