Skip to main content

time_tracker_plugin_sdk/
plugin.rs

1//! Plugin trait and metadata
2
3use serde_json;
4
5/// Plugin metadata
6#[derive(Debug, Clone)]
7pub struct PluginInfo {
8    pub id: String,
9    pub name: String,
10    pub version: String,
11    pub description: Option<String>,
12}
13
14/// Plugin trait that all plugins must implement
15pub trait Plugin: Send + Sync {
16    /// Get plugin metadata
17    fn info(&self) -> &PluginInfo;
18    
19    /// Initialize the plugin
20    fn initialize(&mut self, api: &dyn crate::api::PluginAPIInterface) -> Result<(), String>;
21    
22    /// Invoke a command on the plugin
23    /// The api parameter provides database access and other core functionality
24    fn invoke_command(&self, command: &str, params: serde_json::Value, api: &dyn crate::api::PluginAPIInterface) -> Result<serde_json::Value, String>;
25    
26    /// Shutdown the plugin
27    fn shutdown(&self) -> Result<(), String>;
28    
29    /// Get schema extensions that this plugin requires
30    /// This allows plugins to declare their own database tables and schema changes
31    fn get_schema_extensions(&self) -> Vec<crate::extensions::SchemaExtension> {
32        vec![]
33    }
34    
35    /// Get frontend bundle bytes (if plugin provides UI)
36    fn get_frontend_bundle(&self) -> Option<Vec<u8>> {
37        None
38    }
39}