提交 b60441e9 编写于 作者: J jingnen

主进程和渲染进程之间进行通信

上级 cd86fce9
......@@ -15,8 +15,13 @@
<p id="notification">
点击通知看看会发生什么。
</p>
<p id="message">
这里的文字会显示来自主进程的消息。
</p>
<button onclick="sendMessage();">点击我</button>
<script src="renderernotif.js"></script>
<!-- <script src="renderernotif.js"></script> -->
<script src="renderer.js"></script>
</body>
</html>
\ No newline at end of file
const { app, BrowserWindow, Menu} = require('electron');
const { app, BrowserWindow, Menu, ipcMain} = require('electron');
const menu = require('./menu');
const path = require('path');
const tray = require('./tray');
......@@ -12,7 +12,11 @@ function createWindow () {
width: 800,
height: 600,
icon: iconPath,
show: false
show: false,
webPreferences: {
nodeIntegration: true,
contextIsolation: false
}
});
mainWindow.loadFile('index.html')
......@@ -34,6 +38,10 @@ app.on('ready', () => {
});
});
ipcMain.on('message-request', (event, arg) => {
event.reply('message-reply', '我是来自主进程的消息!');
})
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
......
const { ipcRenderer } = require("electron");
function sendMessage() {
ipcRenderer.send('message-request');
}
ipcRenderer.on('message-reply', (event, arg) => {
document.getElementById('message').innerText = arg;
});
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册