插件说明
介绍
将通用业务做成插件,并挂载到 app.addon 对象上,扩展框架能力。
目录
bash
./electron/addon
addon 目录下面一个插件一个目录
如:example/index.js 其中 example 为 插件名,index.js 为 插件入口文件(框架加载这个入口文件)
编写插件代码
示例
- 编写插件代码
bash
const Log = require('ee-core/log');
const EE = require('ee-core/ee');
/**
* 安全插件
* @class
*/
class SecurityAddon {
constructor() {
}
/**
* 创建
*/
create () {
Log.info('[addon:security] load');
const { CoreApp } = EE;
const runWithDebug = process.argv.find(function(e){
let isHasDebug = e.includes("--inspect") || e.includes("--inspect-brk") || e.includes("--remote-debugging-port");
return isHasDebug;
})
// 不允许远程调试
if (runWithDebug) {
Log.error('[error] Remote debugging is not allowed, runWithDebug:', runWithDebug);
CoreApp.appQuit();
}
}
}
SecurityAddon.toString = () => '[class SecurityAddon]';
module.exports = SecurityAddon;
- 添加配置
bash
# 打开配置文件 ./electron/config/config.default.js
/**
* 插件功能
* window 官方内置插件
* example demo插件
*/
config.addons = {
window: {
enable: true,
},
// 插件名为key,enable 配置启用
example: {
enable: true,
}
};
3.调用插件
bash
const Addon = require("ee-core/addon");
Addon.get("autoUpdater").checkUpdate();