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>;

    // Provided methods
    fn navigate(
        &self,
        _router: Option<&str>,
        _path: &str,
    ) -> Result<(), PluginError> { ... }
    fn back(&self, _router: Option<&str>) -> Result<(), PluginError> { ... }
    fn forward(&self, _router: Option<&str>) -> Result<(), PluginError> { ... }
    fn set_roundness(&self, _value: &str) -> 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.

Provided Methods§

Source

fn navigate( &self, _router: Option<&str>, _path: &str, ) -> Result<(), PluginError>

Navigates a <router> to path. When router is None the host’s primary router is used. The navigation is applied asynchronously (the host defers it so calling this from inside an event handler is safe).

The default implementation reports the operation as unsupported so existing plugin SDKs continue to compile without change.

Source

fn back(&self, _router: Option<&str>) -> Result<(), PluginError>

Moves a router back one entry in its history (primary router when router is None). Applied asynchronously; see Self::navigate.

Source

fn forward(&self, _router: Option<&str>) -> Result<(), PluginError>

Moves a router forward one entry in its history (primary router when router is None). Applied asynchronously; see Self::navigate.

Source

fn set_roundness(&self, _value: &str) -> Result<(), PluginError>

Sets the global UI corner roundness at runtime. value is a named preset (none/square/sharp/default/round) or a raw pixel base radius (e.g. "3"). Applied asynchronously (the host defers it so calling this from inside an event handler is safe); unrecognized values are ignored.

The default implementation reports the operation as unsupported so existing plugin SDKs continue to compile without change.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§