Initial commit: Example Plugin 3 with async operations
This commit is contained in:
34
README.md
Normal file
34
README.md
Normal file
@@ -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
|
||||
```
|
||||
37
index.js
Normal file
37
index.js
Normal file
@@ -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!');
|
||||
}
|
||||
8
plugin.json
Normal file
8
plugin.json
Normal file
@@ -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"
|
||||
}
|
||||
Reference in New Issue
Block a user