-
Notifications
You must be signed in to change notification settings - Fork 19
Execution API
Managing the execution of Pluggable Electron activation and extension points is done in the renderer. The activation manager needs to be set up before the other features can be used in the renderer.
The activation and execution managers can be imported in the renderer process by requiring pluggable electron. E.g.
import { extensionPoints, activationPoints } from "pluggable-electron"
To access the plugin manager from the renderer, the Plugin Manager must first be initialised in the main process, and facade must be initialised in the renderer. If nodeIntegration is set to true, the facade can be imported directly in the renderer, otherwise this needs to be imported in the preload script. Examples:
- in renderer:
const facade = require("pluggable-electron/facade") - in preload:
const { contextBridge } = require('electron')
const facade = require("pluggable-electron/facade")
contextBridge.exposeInMainWorld("plugins", facade)
All of the items described below can be accessed by importing Pluggable Electron in the renderer except for the Facade. This requires a separate import as described above.
- ExtensionPoint
-
Represents a point in the consumer's code that can be extended by a plugin. The plugin can register a callback or object to the extension point. When the extension point is triggered, the provided function will then be called or object will be returned.
-
activationPoints :
object -
This object contains a register of plugin registrations to an activation points, and the means to work with them.
-
extensionPoints :
object -
This object contains a register of extension points and the means to work with them.
-
facade :
object -
Helper functions to access the plugin management in the main process. Note that the facade needs to be imported separately as "pluggable-electron/facade" as described above. It is then available on the global window object as describe in the Electron documentation
-
plugin :
Object -
A representation of a plugin in the renderer.
Represents a point in the consumer's code that can be extended by a plugin. The plugin can register a callback or object to the extension point. When the extension point is triggered, the provided function will then be called or object will be returned.
Kind: global class
Properties
| Name | Type | Description |
|---|---|---|
| name | string |
Name of the extension point |
-
ExtensionPoint
-
.register(name, response, [priority]) ⇒
void -
.unregister(name) ⇒
void -
.clear() ⇒
void -
.get(name) ⇒
Object|Callback -
.execute(input) ⇒
Array -
.executeSerial(input) ⇒
Promise.<*>
-
.register(name, response, [priority]) ⇒
Register new extension with this extension point. The registered response will be executed (if callback) or returned (if object) when the extension point is executed (see below).
Kind: instance method of ExtensionPoint
| Param | Type | Default | Description |
|---|---|---|---|
| name | string |
Unique name for the extension. | |
| response |
Object | Callback
|
Object to be returned or function to be called by the extension point. | |
| [priority] | number |
0 |
Order priority for execution used for executing in serial. |
Remove an extension from the registry. It will no longer be part of the extension point execution.
Kind: instance method of ExtensionPoint
| Param | Type | Description |
|---|---|---|
| name | string |
Name of the extension to remove. |
Empty the registry of all extensions.
Kind: instance method of ExtensionPoint
Get a specific extension registered with the extension point
Kind: instance method of ExtensionPoint
Returns: Object | Callback - The response of the extension. If this is a function the function is returned, not its response.
| Param | Type | Description |
|---|---|---|
| name | string |
Name of the extension to return |
Execute (if callback) and return or just return (if object) the response for each extension registered to this extension point. Any asynchronous responses will be executed in parallel and the returned array will contain a promise for each of these responses.
Kind: instance method of ExtensionPoint
Returns: Array - List of responses from the extensions.
| Param | Type | Description |
|---|---|---|
| input | * |
Input to be provided as a parameter to each response if response is a callback. |
Execute (if callback) or return (if object) the response for each extension registered to this extension point in serial, feeding the result from the last response as input to the next.
Kind: instance method of ExtensionPoint
Returns: Promise.<*> - Result of the last extension that was called
| Param | Type | Description |
|---|---|---|
| input | * |
Input to be provided as a parameter to the 1st callback |
This object contains a register of plugin registrations to an activation points, and the means to work with them.
Kind: global namespace
-
activationPoints :
object-
.setup(options) ⇒
void -
.register(plugin) ⇒
void -
.trigger(activationPoint) ⇒
Promise.<Boolean>
-
.setup(options) ⇒
Set the renderer options for Pluggable Electron. Should be called before any other Pluggable Electron function in the renderer
Kind: static method of activationPoints
| Param | Type | Default | Description |
|---|---|---|---|
| options | Object |
||
| options.importer | importer |
The callback function used to import the plugin entry points. | |
| [options.presetEPs] |
Boolean | null
|
false |
Whether the Extension Points have been predefined (true), can be created on the fly(false) or should not be provided through the input at all (null). |
Register a plugin with its activation points (as defined in its manifest).
Kind: static method of activationPoints
| Param | Type | Description |
|---|---|---|
| plugin | plugin |
plugin object as provided by the main process. |
Trigger all activations registered to the given activation point. See Plugin. This will call the function with the same name as the activation point on the path specified in the plugin.
Kind: static method of activationPoints
Returns: Promise.<Boolean> - Resolves to true when the activations are complete.
| Param | Type | Description |
|---|---|---|
| activationPoint | string |
Name of the activation to trigger |
This object contains a register of extension points and the means to work with them.
Kind: global namespace
-
extensionPoints :
object-
.add(name) ⇒
void -
.register(name, extension, response, [priority]) ⇒
void -
.get([eps]) ⇒
Object.<ExtensionPoint> -
.execute(name, [input]) ⇒
Array -
.executeSerial(name, [input]) ⇒
Promise.<*>
-
.add(name) ⇒
Create new extension point and add it to the registry.
Kind: static method of extensionPoints
| Param | Type | Description |
|---|---|---|
| name | string |
Name of the extension point. |
Create extension point if it does not exist and then register the given extension to it.
Kind: static method of extensionPoints
| Param | Type | Default | Description |
|---|---|---|---|
| name | String |
Name of the extension point. | |
| extension | String |
Unique name for the extension. | |
| response |
Object | Callback
|
Object to be returned or function to be called by the extension point. | |
| [priority] | Number |
0 |
Order priority for execution used for executing in serial. |
extensionPoints.get([eps]) ⇒ Object.<ExtensionPoint>
Fetch extension points by name, or all if no names are provided.
Kind: static method of extensionPoints
Returns: Object.<ExtensionPoint> - Found extension points
| Param | Type | Description |
|---|---|---|
| [eps] | Array.<string> |
List of names of extension points to fetch |
Call all the extensions registered to an extension point synchronously. See execute on ExtensionPoint. Call this at the point in the base code where you want it to be extended.
Kind: static method of extensionPoints
Returns: Array - Result of Promise.all or Promise.allSettled depending on exitOnError
| Param | Type | Description |
|---|---|---|
| name | string |
Name of the extension point to call |
| [input] | * |
Parameter to provide to the extensions if they are a function |
Calls all the extensions registered to the extension point in serial. See executeSerial on ExtensionPoint Call this at the point in the base code where you want it to be extended.
Kind: static method of extensionPoints
Returns: Promise.<*> - Result of the last extension that was called
| Param | Type | Description |
|---|---|---|
| name | string |
Name of the extension point to call |
| [input] | * |
Parameter to provide to the extensions if they are a function |
Helper functions to access the plugin management in the main process. Note that the facade needs to be imported separately as "pluggable-electron/facade" as described above. It is then available on the global window object as describe in the Electron documentation
Kind: global namespace
-
facade :
object-
.install(spec, [options], [activate]) ⇒
Promise.<plugin> -
.uninstall(name) ⇒
Promise.<boolean> -
.getActive() ⇒
Promise.<Array.<plugin>> -
.update(name) ⇒
Promise.<plugin> -
.toggleActive(plugin, active) ⇒
Promise.<plugin>
-
.install(spec, [options], [activate]) ⇒
facade.install(spec, [options], [activate]) ⇒ Promise.<plugin>
Install a new plugin.
Kind: static method of facade
Returns: Promise.<plugin> - plugin as defined by the main process. Has property cancelled set to true if installation was cancelled in the main process.
| Param | Type | Default | Description |
|---|---|---|---|
| spec | string |
NPM package specifier of the plugin. Any form understood by NPM will work here. See npm-install. | |
| [options] | Object |
The options passed to pacote to fetch the manifest, including version. | |
| [activate] | boolean |
true |
Whether the plugin should be activated on install. |
Mark plugin for removal. It will then be removed the next time the plugin is initialised (as by setupPlugins in the main process).
Kind: static method of facade
Returns: Promise.<boolean> - Whether marking the plugin was successful.
| Param | Type | Description |
|---|---|---|
| name | string |
Name of the plugin to uninstall. |
Fetch a list of all the active plugins.
Kind: static method of facade
Returns: Promise.<Array.<plugin>> - List of plugins as defined by the main process.
facade.update(name) ⇒ Promise.<plugin>
Update a plugin to its latest version.
Kind: static method of facade
Returns: Promise.<plugin> - Updated plugin as defined by the main process.
| Param | Type | Description |
|---|---|---|
| name | string |
Name of the plugin to update. |
facade.toggleActive(plugin, active) ⇒ Promise.<plugin>
Toggle a plugin's active state. This determines if a plugin should be loaded in initialisation.
Kind: static method of facade
Returns: Promise.<plugin> - Updated plugin as defined by the main process.
| Param | Type | Description |
|---|---|---|
| plugin | String |
Plugin to toggle. |
| active | boolean |
Whether plugin should be activated (true) or deactivated (false). |
A representation of a plugin in the renderer.
Kind: global typedef
Properties
| Name | Type | Description |
|---|---|---|
| name | string |
Name of the package. |
| url | string |
The electron url where this plugin is located. |
| activationPoints | Array.<string> |
List of activation points. |
| active | boolean |
Whether this plugin should be activated when its activation points are triggered. |