Skip to main content

PluginContext

Trait PluginContext 

Source
pub trait PluginContext: Send + Sync {
    // Required methods
    fn get_data(&self, path: &str) -> Option<PluginValue>;
    fn set_data(
        &self,
        path: &str,
        value: PluginValue,
    ) -> Result<(), PluginError>;
    fn emit_event(&self, event_type: &str, payload: PluginValue);
    fn get_config(&self, path: &str) -> Option<PluginValue>;
    fn log(&self, level: LogLevel, message: &str);
    fn get_component_property(
        &self,
        component_id: &str,
        property: &str,
    ) -> Option<PluginValue>;
    fn set_component_property(
        &self,
        component_id: &str,
        property: &str,
        value: PluginValue,
    ) -> Result<(), PluginError>;
}
Expand description

Re-export nemo-plugin-api for convenience Context providing API access to plugins at runtime.

This trait is Send + Sync, allowing plugins to use it from background threads and async tasks. Obtain an Arc<dyn PluginContext> via PluginRegistrar::context_arc for shared ownership.

§Data Paths

Data paths use dot-separated notation: "data.my_source.items". Config paths follow the same convention: "app.settings.theme".

§Example

fn read_and_write(ctx: &dyn PluginContext) {
    // Read a value
    if let Some(PluginValue::Integer(count)) = ctx.get_data("metrics.request_count") {
        ctx.log(LogLevel::Info, &format!("Requests: {}", count));
    }

    // Write a value
    ctx.set_data("metrics.last_check", PluginValue::String("now".into())).ok();

    // Emit an event for other plugins/components to observe
    ctx.emit_event("plugin:refresh", PluginValue::Null);
}

Required Methods§

Source

fn get_data(&self, path: &str) -> Option<PluginValue>

Gets data by dot-separated path (e.g. "data.source.field").

Source

fn set_data(&self, path: &str, value: PluginValue) -> Result<(), PluginError>

Sets data at a dot-separated path.

Returns Err if the path is invalid or permission is denied.

Source

fn emit_event(&self, event_type: &str, payload: PluginValue)

Emits a named event with an arbitrary payload.

Events are delivered asynchronously via the host’s event bus.

Source

fn get_config(&self, path: &str) -> Option<PluginValue>

Gets a configuration value by dot-separated path.

Source

fn log(&self, level: LogLevel, message: &str)

Logs a message at the given severity level.

Source

fn get_component_property( &self, component_id: &str, property: &str, ) -> Option<PluginValue>

Gets a component property by component ID and property name.

Returns None if the component or property does not exist.

Source

fn set_component_property( &self, component_id: &str, property: &str, value: PluginValue, ) -> Result<(), PluginError>

Sets a component property by component ID and property name.

Returns Err if the component does not exist or the property is read-only.

Implementors§