wip
This commit is contained in:
parent
a0b0b7a7f8
commit
1060b65e14
|
@ -299,14 +299,23 @@ impl RegisteredPlugin for PersistentPlugin {
|
|||
}
|
||||
}
|
||||
|
||||
fn as_any(self: Arc<Self>) -> Arc<dyn std::any::Any + Send + Sync> {
|
||||
self
|
||||
}
|
||||
|
||||
fn set_ctrlc_handler_guard(&self, guard: ctrlc::Guard) {
|
||||
if let Ok(mut mutable) = self.mutable.lock() {
|
||||
mutable.ctrlc_guard = Some(guard);
|
||||
}
|
||||
}
|
||||
|
||||
fn as_any(self: Arc<Self>) -> Arc<dyn std::any::Any + Send + Sync> {
|
||||
self
|
||||
fn ctrlc(&self) -> Result<(), ShellError> {
|
||||
if let Ok(mutable) = self.mutable.lock() {
|
||||
if let Some(ref running) = mutable.running {
|
||||
return running.interface.ctrlc();
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -61,6 +61,7 @@ impl Handlers {
|
|||
if let Ok(mut handlers) = self.handlers.lock() {
|
||||
handlers.push((id, handler));
|
||||
}
|
||||
|
||||
Ok(Guard {
|
||||
id,
|
||||
handlers: Arc::clone(&self.handlers),
|
||||
|
|
|
@ -262,9 +262,15 @@ impl EngineState {
|
|||
for plugin in std::mem::take(&mut delta.plugins) {
|
||||
if let Some(handlers) = self.ctrlc_handlers.as_ref() {
|
||||
let guard = {
|
||||
let plugin = plugin.clone();
|
||||
// We take a weakref to the plugin so that we don't create a cycle to the
|
||||
// RAII guard that will be stored on the plugin.
|
||||
let plugin = Arc::downgrade(&plugin);
|
||||
handlers.register(Box::new(move || {
|
||||
// If the plugin is still alive, call its ctrlc handler. It should
|
||||
// never be None because the guard is dropped when the plugin is.
|
||||
if let Some(plugin) = plugin.upgrade() {
|
||||
let _ = plugin.ctrlc();
|
||||
}
|
||||
}))?
|
||||
};
|
||||
plugin.set_ctrlc_handler_guard(guard);
|
||||
|
|
Loading…
Reference in New Issue
Block a user