Skip to content

Advanced Plugin Topics

Topher Anselmo edited this page Oct 16, 2023 · 4 revisions

How does plugin loading work?

All of the script files that belong to a plugin are directly inserted/mounted into a <script> tag in the document. They are automatically combined and wrapped inside of a helper function that exposes the tmcp API object. This means that all of the scripts for a plugin are included in their own closure, and can benefit from top-level await.

How do I access Electron or Node APIs?

The electron remote package is available, so you can use require() to access needed APIs. Typically you'd require the remote into an object, and use that to require anything else:

const remote = require('@electron/remote');
const fs = remote.require('fs');
const path = remote.require('path');
// etc.

You can use this require function to load any node_modules you may want to install into your plugin's folder:

const remote = require('@electron/remote');
const path = remote.require('path');
const somePackage = remote.require(path.join(__dirname, 'node_modules', 'package_name'));

Clone this wiki locally