1)目录
|
2)实现
-- simple-package
|-- main.js
'use strict';
module.exports = {
load() {
},
unload() {
},
messages: {
// 菜单中定义的点击菜单后的响应函数
open() {
// 这时打开面板
Editor.Panel.open('simple-package');
},
// 主进程接收到渲染进程的消息后
// 由于子进程发送时,带有回调,因此这里的event.reply为true,就可以给渲染进程回应
"simple-package:say-hello"(event, data) {
Editor.success(data);
if (event.reply) {
event.reply(null, "Fine thank you!");
}
}
},
};
|-- package.json
{
"name": "simple-package",
"main": "main.js",
"main-menu": {
"Panel/Simple Panel": {
"message": "simple-package:open"
}
},
"panel": {
"main": "panel/index.js",
"type": "dockable",
"title": "Simple Panel",
"width": 400,
"height": 300
}
}
`-- panel
`-- index.js
// panel/index.js
Editor.Panel.extend({
style: `
:host { margin: 5px; }
h2 { color: #f90; }
`,
template: `
<h2>标准面板</h2>
<ui-button id="btn">点击</ui-button>
<hr />
<div>状态: <span id="label">--</span></div>
`,
$: {
btn: '#btn',
label: '#label',
},
ready() {
this.$btn.addEventListener('confirm', () => {
// this.$label.innerText = '你好';
// setTimeout(() => {
// this.$label.innerText = '--';
// }, 500);
// 向主进程发送消息
// 并且等待主进程的回应
Editor.Ipc.sendToMain('simple-package:say-hello', 'Panel:How are you?', function (err, data) {
if (err) {
Editor.success("err!");
} else {
Editor.success(data);
}
});
});
},
});
3)运行结果