-
Notifications
You must be signed in to change notification settings - Fork 0
π How to Create a Plugin
This guide will walk you through creating a plugin for the system. Plugins extend functionality by implementing a standard interface and integrating seamlessly into the core system.
To develop a plugin, follow these steps:
-
Create a new folder inside the
plugins
directory. - Implement the Plugin interface within this folder.
- Add the plugin to the manager.
- Define the pluginβs configuration for integration and execution.
Each plugin must implement the following methods:
Method | Signature | Description |
---|---|---|
Initialize | Initialize() | Runs before processing the ActivityWatch (AW) data. Used for setup tasks. |
Execute | Execute(watcher string, events Events, userID string, includeHostName bool) | Processes the AW data and executes the core logic. |
ReplicateConfig | ReplicateConfig(path string) | Replicates the pluginβs configuration (for service purposes). |
RawName | RawName() string | Returns the moduleβs raw name. |
Name | Name() string | Returns the formatted configuration name, following the format aw-plugin-{RawName}.yaml. |
Hereβs a basic example of a plugin implementing the interface:
package exampleplugin
import (
"fmt"
)
type ExamplePlugin struct {}
func (p *ExamplePlugin) Initialize() {
fmt.Println("Initializing Example Plugin...")
}
func (p *ExamplePlugin) Execute(watcher string, events Events, userID string, includeHostName bool) {
fmt.Printf("Executing plugin for watcher: %s with user ID: %s\n", watcher, userID)
}
func (p *ExamplePlugin) ReplicateConfig(path string) {
fmt.Printf("Replicating config to: %s\n", path)
}
func (p *ExamplePlugin) RawName() string {
return "example"
}
func (p *ExamplePlugin) Name() string {
return "aw-plugin-example.yaml"
}
Ensure your plugin follows this folder structure:
plugins/
βββ exampleplugin/
β βββ plugin.go (basic inheritance of a plugin)
β βββ operations.go (operations of the plugin)
| βββ config.go (if there is a configuration of the plugin)
Once your plugin is ready:
- Place it in the
plugins
directory. - Ensure it implements all required methods.
- Register it within the system for execution.
- Test your plugin with sample AW data.
- Extend functionality based on specific use cases.
- Contribute to the system by submitting a PR with your plugin!