在 automationEvents 中声明自动化事件用于工作流编排。
下面是一个示例:
const path = require('path');
const { BrowserWindow, Notification } = require('electron');
const functions = {
hello: (from) => `Hello ${from || ''}!`,
openSettings: async () => {
const win = new BrowserWindow({
width: 800, height: 500, title: 'Example Plugin', frame: false,
titleBarStyle: 'hidden', webPreferences: { preload: path.join(__dirname, 'preload.js'), nodeIntegration: false, contextIsolation: true }
});
win.loadFile(path.join(__dirname, 'index.html'));
win.show();
return true;
},
notify: (title = '自动化示例', body = '') => {
try { new Notification({ title: String(title), body: String(body) }).show(); return true; } catch { return false; }
},
logTime: () => {
try { const fs = require('fs'); const p = path.join(__dirname, 'automation.log'); fs.appendFileSync(p, new Date().toISOString() + '\n', 'utf-8'); return p; } catch { return null; }
}
};
const automationEvents = [
{ id: 'notify', name: 'notify', desc: '系统通知', params: [ { name: 'title', type: 'string', hint: '通知标题' }, { name: 'body', type: 'string', hint: '通知内容' } ] },
{ id: 'logTime', name: 'logTime', desc: '时间写入日志文件', params: [] }
];
const init = async (api) => {
api.splash.setStatus('plugin:init', '初始化');
// 执行耗时任务...
api.splash.setStatus('plugin:init', '加载完成');
};
module.exports = { name: '测试插件', version: '1.0.0', init, functions, automationEvents };