From 3bb85bd1015b47fa381dd5d93e938711e77017e9 Mon Sep 17 00:00:00 2001 From: Max Litruv Boonzaayer Date: Fri, 17 Apr 2026 03:00:27 +1000 Subject: [PATCH] Initial commit: Example Plugin 3 with async operations --- README.md | 34 ++++++++++++++++++++++++++++++++++ index.js | 37 +++++++++++++++++++++++++++++++++++++ plugin.json | 8 ++++++++ 3 files changed, 79 insertions(+) create mode 100644 README.md create mode 100644 index.js create mode 100644 plugin.json diff --git a/README.md b/README.md new file mode 100644 index 0000000..1854bd3 --- /dev/null +++ b/README.md @@ -0,0 +1,34 @@ +# Example Plugin 3 + +A third example plugin demonstrating async operations and simple data storage. + +## Features + +- Async data fetching hook +- Data storage hook +- Periodic status reporting + +## Hooks + +### fetch-data +Retrieves stored data by key. + +**Usage:** +```javascript +const value = await context.runHook('fetch-data', 'myKey'); +``` + +### store-data +Stores data with a key. + +**Usage:** +```javascript +await context.runHook('store-data', 'myKey', 'myValue'); +``` + +## Installation + +Install via Plugin Host interactive installer or manually clone: +```bash +git clone http://synbox.ruv.wtf:8418/litruv/Plugin-Example3.git +``` diff --git a/index.js b/index.js new file mode 100644 index 0000000..b537f81 --- /dev/null +++ b/index.js @@ -0,0 +1,37 @@ +/** + * Example Plugin 3 - Async Operations & Storage + */ + +let dataStore = {}; +let intervalId = null; + +export async function activate(context) { + context.log('Example Plugin 3 activated!'); + + // Register async data hook + context.registerHook('fetch-data', async (key) => { + context.log(`Fetching data for key: ${key}`); + await new Promise(resolve => setTimeout(resolve, 100)); // Simulate async operation + return dataStore[key] || null; + }); + + // Register data storage hook + context.registerHook('store-data', async (key, value) => { + context.log(`Storing data: ${key} = ${value}`); + dataStore[key] = value; + return true; + }); + + // Periodic status report + intervalId = setInterval(() => { + const keys = Object.keys(dataStore).length; + context.log(`Storage status: ${keys} entries`); + }, 30000); +} + +export async function deactivate(context) { + if (intervalId) { + clearInterval(intervalId); + } + context.log('Example Plugin 3 deactivated!'); +} diff --git a/plugin.json b/plugin.json new file mode 100644 index 0000000..f510876 --- /dev/null +++ b/plugin.json @@ -0,0 +1,8 @@ +{ + "id": "litruv-example-plugin-3", + "name": "Example Plugin 3", + "version": "1.0.0", + "description": "A third example plugin demonstrating async operations and data storage", + "main": "index.js", + "author": "litruv" +}