feat: Support context options
This commit is contained in:
parent
a852584a0d
commit
dae8108cb1
8 changed files with 220 additions and 37 deletions
16
service/src/plugins/external/mod.rs
vendored
16
service/src/plugins/external/mod.rs
vendored
|
|
@ -9,7 +9,7 @@ use std::{
|
|||
},
|
||||
};
|
||||
|
||||
use crate::{Event, Plugin, PluginResponse, Request};
|
||||
use crate::{Event, Indice, Plugin, PluginResponse, Request};
|
||||
use async_oneshot::oneshot;
|
||||
use futures_lite::{AsyncWriteExt, FutureExt, StreamExt};
|
||||
use postage::mpsc::Sender;
|
||||
|
|
@ -168,14 +168,22 @@ impl ExternalPlugin {
|
|||
|
||||
#[async_trait::async_trait]
|
||||
impl Plugin for ExternalPlugin {
|
||||
async fn activate(&mut self, id: u32) {
|
||||
async fn activate(&mut self, id: Indice) {
|
||||
let _ = self.query(&Request::Activate(id)).await;
|
||||
}
|
||||
|
||||
async fn complete(&mut self, id: u32) {
|
||||
async fn activate_context(&mut self, id: Indice, context: Indice) {
|
||||
let _ = self.query(&Request::ActivateContext { id, context }).await;
|
||||
}
|
||||
|
||||
async fn complete(&mut self, id: Indice) {
|
||||
let _ = self.query(&Request::Complete(id)).await;
|
||||
}
|
||||
|
||||
async fn context(&mut self, id: Indice) {
|
||||
let _ = self.query(&Request::Context(id)).await;
|
||||
}
|
||||
|
||||
fn exit(&mut self) {
|
||||
if let Some((_, _, mut trigger)) = self.process.take() {
|
||||
let _ = trigger.send(());
|
||||
|
|
@ -200,7 +208,7 @@ impl Plugin for ExternalPlugin {
|
|||
.await;
|
||||
}
|
||||
}
|
||||
async fn quit(&mut self, id: u32) {
|
||||
async fn quit(&mut self, id: Indice) {
|
||||
let _ = self.query(&Request::Quit(id)).await;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -58,10 +58,14 @@ impl Plugin for HelpPlugin {
|
|||
}
|
||||
}
|
||||
|
||||
async fn activate_context(&mut self, _: u32, _: u32) {}
|
||||
|
||||
async fn complete(&mut self, id: u32) {
|
||||
self.activate(id).await
|
||||
}
|
||||
|
||||
async fn context(&mut self, _: u32) {}
|
||||
|
||||
fn exit(&mut self) {}
|
||||
|
||||
async fn interrupt(&mut self) {}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ pub use self::config::{PluginBinary, PluginConfig, PluginQuery};
|
|||
pub use self::external::ExternalPlugin;
|
||||
pub use self::help::HelpPlugin;
|
||||
|
||||
use crate::{PluginHelp, Request};
|
||||
use crate::{Indice, PluginHelp, Request};
|
||||
use async_trait::async_trait;
|
||||
use postage::mpsc::{Receiver, Sender};
|
||||
use postage::prelude::*;
|
||||
|
|
@ -18,9 +18,13 @@ where
|
|||
Self: Sized + Send,
|
||||
{
|
||||
/// Activate the selected ID from this plugin
|
||||
async fn activate(&mut self, id: u32);
|
||||
async fn activate(&mut self, id: Indice);
|
||||
|
||||
async fn complete(&mut self, id: u32);
|
||||
async fn activate_context(&mut self, id: Indice, context: Indice);
|
||||
|
||||
async fn complete(&mut self, id: Indice);
|
||||
|
||||
async fn context(&mut self, id: Indice);
|
||||
|
||||
fn exit(&mut self);
|
||||
|
||||
|
|
@ -30,7 +34,7 @@ where
|
|||
|
||||
async fn search(&mut self, query: &str);
|
||||
|
||||
async fn quit(&mut self, id: u32);
|
||||
async fn quit(&mut self, id: Indice);
|
||||
|
||||
async fn run(&mut self, mut rx: Receiver<Request>) {
|
||||
while let Some(request) = rx.recv().await {
|
||||
|
|
@ -44,7 +48,11 @@ where
|
|||
Request::Search(query) => self.search(&query).await,
|
||||
Request::Interrupt => self.interrupt().await,
|
||||
Request::Activate(id) => self.activate(id).await,
|
||||
Request::ActivateContext { id, context } => {
|
||||
self.activate_context(id, context).await
|
||||
}
|
||||
Request::Complete(id) => self.complete(id).await,
|
||||
Request::Context(id) => self.context(id).await,
|
||||
Request::Quit(id) => self.quit(id).await,
|
||||
Request::Exit => {
|
||||
self.exit();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue