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 (--desktopbuilds only)desktop.ready- Run after the application is ready (--desktopbuilds only)desktop.load- Run after each window is created in the application (--desktopbuilds only)desktop.unload- Run after each window is closed (--desktopbuilds only)desktop.end- Run before the app exits (--desktopbuilds only)
Note: Official plugins can be found in the
@commonersnamespace 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: {
load: ({ DEV, WEB, DESKTOP, MOBILE }) => DEV || DESKTOP,
start: ({ DEV, DESKTOP }) => DEV || DESKTOP,
ready: ({ DEV, DESKTOP }) => DEV || DESKTOP,
quit: ({ DEV, DESKTOP }) => DEV || DESKTOP,
},
load: () => console.log(commoners.target + ' application (load)'),
start: ( serviceConfigs ) => console.log('application (start)'),
ready: ( activeServices ) => console.log('application build (ready)'),
quit: () => console.log('application build (quit)'),
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.