reactive_graph_sys_file/
plugin.rs1use crate::behaviour::component::FsNotifyFactory;
2use reactive_graph_plugin_api::EntityComponentBehaviourRegistry;
3use reactive_graph_plugin_api::prelude::plugin::*;
4use reactive_graph_plugin_api::prelude::providers::*;
5use reactive_graph_sys_file_model::BEHAVIOUR_FS_NOTIFY;
6use reactive_graph_sys_file_model::COMPONENT_BEHAVIOUR_FS_NOTIFY;
7
8export_plugin!({
9 "dependencies": [
10 { "name": "reactive-graph-std-base", "version": ">=0.10.0, <0.11.0" }
11 { "name": "reactive-graph-std-trigger", "version": ">=0.10.0, <0.11.0" }
12 ]
13});
14
15#[injectable]
16pub trait FilePlugin: Plugin + Send + Sync {}
17
18#[derive(Component)]
19pub struct FilePluginImpl {
20 component_provider: Arc<dyn TypeProvider<Components> + Send + Sync>,
21
22 #[component(default = "component_provider_registry")]
23 component_provider_registry: Arc<dyn ComponentProviderRegistry + Send + Sync>,
24
25 #[component(default = "entity_component_behaviour_registry")]
26 entity_component_behaviour_registry: Arc<dyn EntityComponentBehaviourRegistry + Send + Sync>,
27}
28
29#[async_trait]
30#[component_alias]
31impl Plugin for FilePluginImpl {
32 async fn activate(&self) -> Result<(), PluginActivationError> {
33 self.component_provider_registry.register_provider(self.component_provider.clone()).await;
34 self.entity_component_behaviour_registry
35 .register(COMPONENT_BEHAVIOUR_FS_NOTIFY.clone(), Arc::new(FsNotifyFactory::new(BEHAVIOUR_FS_NOTIFY.clone())))
36 .await;
37 Ok(())
38 }
39
40 async fn deactivate(&self) -> Result<(), PluginDeactivationError> {
41 self.entity_component_behaviour_registry.unregister(&COMPONENT_BEHAVIOUR_FS_NOTIFY).await;
42 self.component_provider_registry.unregister_provider(self.component_provider.id()).await;
43 Ok(())
44 }
45}