简体   繁体   English

如何在Electron中处理面向用户的插件?

[英]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. 我想在我的Electron应用程序中添加一个插件系统,以便我的用户可以在我的应用程序中添加新功能。 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. .zip让我的用户上传一个包含插件的.zip ,然后将其解压缩,并要求该插件在应用程序中使用它。 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 )? 由于不能使用npm (例如lodash ),应如何处理具有依赖性的插件?
  2. How can I give the plugin an API to use (eg getting application theme or resource name) 如何为插件提供要使用的API(例如,获取应用程序主题或资源名称)

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. 我的最终目标是拥有一个在Electron中工作的系统,类似于Wordpress插件的工作方式。

You could use npm as a child process. 您可以将npm用作子进程。

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 或使用一个库作为示例: https : //github.com/getstation/electron-package-manager

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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