简体   繁体   中英

How should I handle user-facing plugins in Electron?

I would like to add a plugin system to my Electron application so that my users can add new features to my application. I was originally thinking that I would let my users upload a .zip containing a plugin and then it would extract, and require the plugin to use it within the application. I then ran into problems with the idea.

  1. How should I handle a plugin which has dependencies since I cannot use npm (eg lodash )?
  2. How can I give the plugin an API to use (eg getting application theme or resource name)

I am not sure how this could be handled, I've looked around for similar cases but haven't found them. My ultimate goal is to have a system that works in Electron similar to how Wordpress plugins work.

You could use npm as a child process.

You can implement your own:

require('child_process').exec(
  'npm ...',
  { maxBuffer: 1024 * 500 },
  function (error, stdout, stderr) {
    var response = JSON.parse(stdout).dependencies;
    ...
  }
);

or use a library, as an example: https://github.com/getstation/electron-package-manager

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM