Merge pull request #219 from j4qfrost/bridge-signal

Signal bridge shutdown
macos-click-through
Keith Simmons 5 years ago committed by GitHub
commit 6412a3ac8a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -6,6 +6,7 @@ mod handler;
mod ui_commands; mod ui_commands;
use std::process::Stdio; use std::process::Stdio;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc; use std::sync::Arc;
use log::{error, info, trace}; use log::{error, info, trace};
@ -94,7 +95,7 @@ async fn start_process(mut receiver: UnboundedReceiver<UiCommand>) {
} }
Ok(Ok(())) => {} Ok(Ok(())) => {}
}; };
std::process::exit(0); BRIDGE.running.store(false, Ordering::Relaxed);
}); });
if let Ok(Value::Integer(correct_version)) = nvim.eval("has(\"nvim-0.4\")").await { if let Ok(Value::Integer(correct_version)) = nvim.eval("has(\"nvim-0.4\")").await {
@ -131,6 +132,9 @@ async fn start_process(mut receiver: UnboundedReceiver<UiCommand>) {
tokio::spawn(async move { tokio::spawn(async move {
info!("UiCommand processor started"); info!("UiCommand processor started");
while let Some(commands) = drain(&mut receiver).await { while let Some(commands) = drain(&mut receiver).await {
if !BRIDGE.running.load(Ordering::Relaxed) {
return;
}
let (resize_list, other_commands): (Vec<UiCommand>, Vec<UiCommand>) = commands let (resize_list, other_commands): (Vec<UiCommand>, Vec<UiCommand>) = commands
.into_iter() .into_iter()
.partition(|command| command.is_resize()); .partition(|command| command.is_resize());
@ -143,6 +147,9 @@ async fn start_process(mut receiver: UnboundedReceiver<UiCommand>) {
{ {
let input_nvim = input_nvim.clone(); let input_nvim = input_nvim.clone();
tokio::spawn(async move { tokio::spawn(async move {
if !BRIDGE.running.load(Ordering::Relaxed) {
return;
}
trace!("Executing UiCommand: {:?}", &command); trace!("Executing UiCommand: {:?}", &command);
command.execute(&input_nvim).await; command.execute(&input_nvim).await;
}); });
@ -161,6 +168,7 @@ async fn start_process(mut receiver: UnboundedReceiver<UiCommand>) {
pub struct Bridge { pub struct Bridge {
_runtime: Runtime, // Necessary to keep runtime running _runtime: Runtime, // Necessary to keep runtime running
sender: UnboundedSender<UiCommand>, sender: UnboundedSender<UiCommand>,
pub running: AtomicBool,
} }
impl Bridge { impl Bridge {
@ -171,14 +179,17 @@ impl Bridge {
runtime.spawn(async move { runtime.spawn(async move {
start_process(receiver).await; start_process(receiver).await;
}); });
Bridge { Bridge {
_runtime: runtime, _runtime: runtime,
sender, sender,
running: AtomicBool::new(true),
} }
} }
pub fn queue_command(&self, command: UiCommand) { pub fn queue_command(&self, command: UiCommand) {
if !BRIDGE.running.load(Ordering::Relaxed) {
return;
}
trace!("UiCommand queued: {:?}", &command); trace!("UiCommand queued: {:?}", &command);
self.sender.send(command).unwrap_or_explained_panic( self.sender.send(command).unwrap_or_explained_panic(
"Could not send UI command from the window system to the neovim process.", "Could not send UI command from the window system to the neovim process.",

Loading…
Cancel
Save