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)運行結果