Skip to content

πŸ“ How to Create a Plugin

Phillip Rafail Papadakis edited this page Feb 6, 2025 · 2 revisions

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.

πŸ“Œ Core Plugin Structure

To develop a plugin, follow these steps:

  1. Create a new folder inside the plugins directory.
  2. Implement the Plugin interface within this folder.
  3. Add the plugin to the manager.
  4. Define the plugin’s configuration for integration and execution.

πŸ› οΈ Plugin Interface

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.

πŸ”§ Example Plugin Implementation

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" }

πŸ“ Plugin Folder Structure

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)

πŸ”— Integrating the Plugin

Once your plugin is ready:

  1. Place it in the plugins directory.
  2. Ensure it implements all required methods.
  3. Register it within the system for execution.

βœ… Next Steps

  • 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!