reactive_graph_sys_system_environment/
plugin.rs1use crate::factory::SystemEnvironmentReactiveEntityFactory;
2use reactive_graph_plugin_api::prelude::plugin::*;
3use reactive_graph_plugin_api::prelude::providers::*;
4
5export_plugin!({
6 "dependencies": [
7 { "name": "reactive-graph-std-base", "version": ">=0.10.0, <0.11.0" },
8 { "name": "reactive-graph-std-value", "version": ">=0.10.0, <0.11.0" }
9 ]
10});
11
12#[derive(Component)]
13pub struct SystemEnvironmentPlugin {
14 entity_types_provider: Arc<dyn TypeProvider<EntityTypes> + Send + Sync>,
15
16 factory: Arc<SystemEnvironmentReactiveEntityFactory>,
17
18 #[component(default = "entity_types_provider_registry")]
19 entity_type_provider_registry: Arc<dyn EntityTypeProviderRegistry + Send + Sync>,
20}
21
22#[async_trait]
23#[component_alias]
24impl Plugin for SystemEnvironmentPlugin {
25 async fn activate(&self) -> Result<(), PluginActivationError> {
26 self.entity_type_provider_registry.register_provider(self.entity_types_provider.clone()).await;
27 if let Err(e) = self.factory.create_entity_instances().await {
28 return Err(PluginActivationError::ActivationFailed(format!(
29 "Failed to create entities which represents the system environment variables: {e}"
30 )));
31 }
32 Ok(())
33 }
34
35 async fn deactivate(&self) -> Result<(), PluginDeactivationError> {
36 self.entity_type_provider_registry.unregister_provider(self.entity_types_provider.id()).await;
37 Ok(())
38 }
39}