Plugins
Plugins are collections of JavaScript functions that run at different points during app initialization. These points include:
load
- After the DOM is loadeddesktop.start
- Run on application launch (--desktop
builds only)desktop.ready
- Run after the application is ready (--desktop
builds only)desktop.load
- Run after each window is created in the application (--desktop
builds only)desktop.unload
- Run after each window is closed (--desktop
builds only)desktop.end
- Run before the app exits (--desktop
builds only)
Note: Official plugins can be found in the
@commoners
namespace on NPM, and are listed in the official plugins section.
To add a new plugin, simply provide a named Plugin
on the plugins
registry of your Configuration File:
js
export default {
plugins: {
selectiveBuild: {
isSupported: {
web: {
load: false
}
},
load: () => console.log(commoners.target + ' build (load)'),
desktop: {
load: () => console.log('desktop build (load)'),
unload: () => console.log('desktop build (unload)')
}
}
}
}
To use a plugin, you should check for the existence of the plugin, which may have a return value stored in the PLUGINS
property.
However, some plugins are asynchronously loaded. You can use the READY
promise to ensure you're working with the resolved plugins:
js
const { READY } = commoners
READY.then(({ selectiveBuild }) => {
if (selectiveBuild) console.log('Loaded!')
})
Global variables will be loaded from your .env
file (if present). which you can use in desktop
load functions.