Skip to content

Open-source download manager & offline media toolbox for YouTube, music, social media, learning platforms & 1,800+ sites. Built with Tauri 2.0, Rust & Svelte.

feat: add OmnigetPlugin trait and export_plugin macro for plugin integration

Tonho6a27de66cd74
diff --git a/src-tauri/omniget-plugin-sdk/src/plugin.rs b/src-tauri/omniget-plugin-sdk/src/plugin.rs
new file mode 100644
index 00000000..0213080f
--- /dev/null
+++ b/src-tauri/omniget-plugin-sdk/src/plugin.rs
@@ -0,0 +1,35 @@
+use std::sync::Arc;
+
+use crate::host::PluginHost;
+
+pub trait OmnigetPlugin: Send + Sync {
+ fn id(&self) -> &str;
+ fn name(&self) -> &str;
+ fn version(&self) -> &str;
+ fn initialize(&mut self, host: Arc<dyn PluginHost>) -> anyhow::Result<()>;
+ fn shutdown(&self) {}
+
+ fn handle_command(
+ &self,
+ command: &str,
+ args: serde_json::Value,
+ ) -> std::pin::Pin<Box<dyn std::future::Future<Output = Result<serde_json::Value, String>> + Send + '_>>;
+
+ fn commands(&self) -> Vec<String>;
+}
+
+#[macro_export]
+macro_rules! export_plugin {
+ ($constructor:expr) => {
+ #[no_mangle]
+ pub extern "C" fn omniget_plugin_abi_version() -> u32 {
+ $crate::ABI_VERSION
+ }
+
+ #[no_mangle]
+ pub extern "C" fn omniget_plugin_init() -> *mut dyn $crate::OmnigetPlugin {
+ let plugin = $constructor;
+ Box::into_raw(Box::new(plugin))
+ }
+ };
+}