Actually call template functions

This commit is contained in:
Gregory Schier
2024-08-19 10:34:22 -07:00
parent 1fbcfeaa30
commit 0f8aea3afd
19 changed files with 284 additions and 216 deletions

View File

@@ -0,0 +1,25 @@
use std::collections::HashMap;
use tauri::{AppHandle, Manager};
use yaak_plugin_runtime::manager::PluginManager;
use yaak_templates::TemplateCallback;
pub struct PluginTemplateCallback {
app_handle: AppHandle,
}
impl PluginTemplateCallback {
pub fn new(app_handle: AppHandle) -> PluginTemplateCallback {
PluginTemplateCallback { app_handle }
}
}
impl TemplateCallback for PluginTemplateCallback {
async fn run(&self, fn_name: &str, args: HashMap<String, String>) -> Result<String, String> {
let plugin_manager = self.app_handle.state::<PluginManager>();
let resp = plugin_manager
.call_template_function(fn_name, args)
.await
.map_err(|e| e.to_string())?;
Ok(resp.unwrap_or_default())
}
}