Skip to main content

eov_plugin_api/
lib.rs

1//! The eov plugin API.
2//!
3//! An eov plugin is a native library (`cdylib`) that implements
4//! [`sdk::Plugin`] and exports it with [`export_plugin!`]. The host talks to
5//! it through a small, layout-checked ABI ([`abi`]) carrying JSON messages
6//! defined in [`protocol`]; the SDK hides both behind safe Rust types.
7//!
8//! ```no_run
9//! use eov_plugin_api::prelude::*;
10//!
11//! struct Counter {
12//!     host: Host,
13//! }
14//!
15//! impl Plugin for Counter {
16//!     fn create(host: Host, _init: PluginInit) -> Result<Self, String> {
17//!         Ok(Self { host })
18//!     }
19//!
20//!     fn on_event(&self, event: HostEvent) -> Result<(), String> {
21//!         if let HostEvent::FileOpened { file } = event {
22//!             self.host.info(format!("{} opened", file.filename));
23//!         }
24//!         Ok(())
25//!     }
26//! }
27//!
28//! eov_plugin_api::export_plugin!(Counter);
29//! ```
30//!
31//! A plugin package (`.eop`) is a tar archive holding `plugin.toml` (see
32//! [`manifest`]), the library and any `.slint` files and assets. See the
33//! crate README and `example-plugin/` for a complete walkthrough, and
34//! [`testing`] for unit-testing plugins without eov.
35
36pub mod abi;
37pub mod i18n;
38pub mod manifest;
39pub mod protocol;
40pub mod sdk;
41pub mod testing;
42
43pub use manifest::PluginManifest;
44
45/// Everything a plugin usually needs: `use eov_plugin_api::prelude::*;`.
46pub mod prelude {
47    pub use crate::abi::{FfiErrorKind, FilterView, RegionRequest, SlideRegion};
48    pub use crate::i18n::tr;
49    pub use crate::protocol::*;
50    pub use crate::sdk::{
51        Frame, Host, HostError, HostResult, Image, Job, Layer, Plugin, SlideReader, Surface,
52    };
53    pub use serde_json::{Map, Value, json};
54}
55
56/// Re-exports used by [`export_plugin!`]; not part of the public API.
57#[doc(hidden)]
58pub mod __private {
59    pub use abi_stable::library::{
60        __call_root_module_loader as call_root_module_loader, CheckTypeLayout, LibHeader,
61        RootModuleResult,
62    };
63}
64
65use std::path::PathBuf;
66use thiserror::Error;
67
68/// Errors raised while reading plugin packages and manifests.
69#[derive(Debug, Error)]
70pub enum PluginError {
71    #[error("plugin manifest error in '{plugin_id}': {message}")]
72    Manifest { plugin_id: String, message: String },
73    #[error("plugin '{plugin_id}' missing required file: {path}")]
74    MissingFile { plugin_id: String, path: PathBuf },
75    #[error("duplicate plugin id: '{0}'")]
76    DuplicateId(String),
77    #[error("IO error: {0}")]
78    Io(#[from] std::io::Error),
79    #[error("{0}")]
80    Other(String),
81}
82
83pub type PluginResult<T> = Result<T, PluginError>;
84
85/// How a plugin's icon is provided in its manifest.
86#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
87#[serde(tag = "kind", rename_all = "snake_case")]
88pub enum IconDescriptor {
89    /// Inline SVG.
90    Svg { data: String },
91    /// Path to an image, relative to the plugin root.
92    File { path: PathBuf },
93}
94
95/// A discovered plugin package: its extracted root and parsed manifest.
96#[derive(Debug, Clone)]
97pub struct PluginDescriptor {
98    /// Absolute path to the extracted plugin root.
99    pub root: PathBuf,
100    pub manifest: PluginManifest,
101}