mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-23 01:49:13 +01:00
Reload template functions on window focus
This commit is contained in:
@@ -21,11 +21,11 @@ pub struct InternalEvent {
|
||||
#[serde(rename_all = "snake_case", tag = "type")]
|
||||
#[ts(export)]
|
||||
pub enum InternalEventPayload {
|
||||
BootRequest(PluginBootRequest),
|
||||
BootResponse(PluginBootResponse),
|
||||
BootRequest(BootRequest),
|
||||
BootResponse(BootResponse),
|
||||
|
||||
ReloadRequest(EmptyResponse),
|
||||
ReloadResponse(EmptyResponse),
|
||||
ReloadRequest,
|
||||
ReloadResponse,
|
||||
|
||||
ImportRequest(ImportRequest),
|
||||
ImportResponse(ImportResponse),
|
||||
@@ -63,25 +63,20 @@ pub enum InternalEventPayload {
|
||||
|
||||
/// Returned when a plugin doesn't get run, just so the server
|
||||
/// has something to listen for
|
||||
EmptyResponse(EmptyResponse),
|
||||
EmptyResponse,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default, Serialize, Deserialize, TS)]
|
||||
#[serde(default)]
|
||||
#[ts(export, type = "{}")]
|
||||
pub struct EmptyResponse {}
|
||||
|
||||
#[derive(Debug, Clone, Default, Serialize, Deserialize, TS)]
|
||||
#[serde(default, rename_all = "camelCase")]
|
||||
#[ts(export)]
|
||||
pub struct PluginBootRequest {
|
||||
pub struct BootRequest {
|
||||
pub dir: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default, Serialize, Deserialize, TS)]
|
||||
#[serde(default, rename_all = "camelCase")]
|
||||
#[ts(export)]
|
||||
pub struct PluginBootResponse {
|
||||
pub struct BootResponse {
|
||||
pub name: String,
|
||||
pub version: String,
|
||||
pub capabilities: Vec<String>,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::events::{EmptyResponse, InternalEvent, InternalEventPayload, PluginBootResponse};
|
||||
use crate::events::{BootResponse, InternalEvent, InternalEventPayload};
|
||||
use crate::server::plugin_runtime::EventStreamEvent;
|
||||
use crate::util::gen_id;
|
||||
use std::sync::Arc;
|
||||
@@ -9,7 +9,7 @@ pub struct PluginHandle {
|
||||
pub ref_id: String,
|
||||
pub dir: String,
|
||||
pub(crate) to_plugin_tx: Arc<Mutex<mpsc::Sender<tonic::Result<EventStreamEvent>>>>,
|
||||
pub(crate) boot_resp: Arc<Mutex<Option<PluginBootResponse>>>,
|
||||
pub(crate) boot_resp: Arc<Mutex<Option<BootResponse>>>,
|
||||
}
|
||||
|
||||
impl PluginHandle {
|
||||
@@ -20,7 +20,7 @@ impl PluginHandle {
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn info(&self) -> Option<PluginBootResponse> {
|
||||
pub async fn info(&self) -> Option<BootResponse> {
|
||||
let resp = &*self.boot_resp.lock().await;
|
||||
resp.clone()
|
||||
}
|
||||
@@ -39,7 +39,7 @@ impl PluginHandle {
|
||||
}
|
||||
|
||||
pub async fn reload(&self) -> crate::error::Result<()> {
|
||||
let event = self.build_event_to_send(&InternalEventPayload::ReloadRequest(EmptyResponse{}), None);
|
||||
let event = self.build_event_to_send(&InternalEventPayload::ReloadRequest, None);
|
||||
self.send(&event).await
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ impl PluginHandle {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn boot(&self, resp: &PluginBootResponse) {
|
||||
pub async fn boot(&self, resp: &BootResponse) {
|
||||
let mut boot_resp = self.boot_resp.lock().await;
|
||||
*boot_resp = Some(resp.clone());
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use crate::error::Result;
|
||||
use crate::events::{
|
||||
PluginBootResponse, CallHttpRequestActionRequest, CallTemplateFunctionArgs,
|
||||
BootResponse, CallHttpRequestActionRequest, CallTemplateFunctionArgs,
|
||||
CallTemplateFunctionRequest, CallTemplateFunctionResponse, FilterRequest, FilterResponse,
|
||||
GetHttpRequestActionsRequest, GetHttpRequestActionsResponse, GetTemplateFunctionsResponse,
|
||||
ImportRequest, ImportResponse, InternalEvent, InternalEventPayload, RenderPurpose,
|
||||
@@ -69,7 +69,7 @@ impl PluginManager {
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn get_plugin_info(&self, dir: &str) -> Option<PluginBootResponse> {
|
||||
pub async fn get_plugin_info(&self, dir: &str) -> Option<BootResponse> {
|
||||
self.server.plugin_by_dir(dir).await.ok()?.info().await
|
||||
}
|
||||
|
||||
@@ -204,7 +204,7 @@ impl PluginManager {
|
||||
|
||||
match event.payload {
|
||||
InternalEventPayload::FilterResponse(resp) => Ok(resp),
|
||||
InternalEventPayload::EmptyResponse(_) => {
|
||||
InternalEventPayload::EmptyResponse => {
|
||||
Err(PluginErr("Filter returned empty".to_string()))
|
||||
}
|
||||
e => Err(PluginErr(format!("Export returned invalid event {:?}", e))),
|
||||
|
||||
@@ -10,7 +10,7 @@ use tonic::{Request, Response, Status, Streaming};
|
||||
|
||||
use crate::error::Error::PluginNotFoundErr;
|
||||
use crate::error::Result;
|
||||
use crate::events::{InternalEvent, InternalEventPayload, PluginBootRequest, PluginBootResponse};
|
||||
use crate::events::{InternalEvent, InternalEventPayload, BootRequest, BootResponse};
|
||||
use crate::handle::PluginHandle;
|
||||
use crate::server::plugin_runtime::plugin_runtime_server::PluginRuntime;
|
||||
use crate::util::gen_id;
|
||||
@@ -75,7 +75,7 @@ impl PluginRuntimeGrpcServer {
|
||||
};
|
||||
}
|
||||
|
||||
pub async fn boot_plugin(&self, id: &str, resp: &PluginBootResponse) {
|
||||
pub async fn boot_plugin(&self, id: &str, resp: &BootResponse) {
|
||||
match self.plugin_ref_to_plugin.lock().await.get(id) {
|
||||
None => println!("Tried booting non-existing plugin {}", id),
|
||||
Some(plugin) => plugin.clone().boot(resp).await,
|
||||
@@ -266,7 +266,7 @@ impl PluginRuntimeGrpcServer {
|
||||
plugin_ids.push(plugin.clone().ref_id);
|
||||
|
||||
let event = plugin.build_event_to_send(
|
||||
&InternalEventPayload::BootRequest(PluginBootRequest {
|
||||
&InternalEventPayload::BootRequest(BootRequest {
|
||||
dir: dir.to_string(),
|
||||
}),
|
||||
None,
|
||||
|
||||
Reference in New Issue
Block a user