javascript - Electron:从 main.js 向 index.js 发送消息
问题描述
在我继续之前,我是电子新手,昨天才开始使用它,所以请详细说明你的答案。
所以我正在创建一个记事本应用程序。我想在单击子菜单时发送消息。这个子菜单和 BrowserWindow 都在main.js
文件中。每当我单击子菜单时,它应该发送一条消息,然后由名为 index.js 的脚本接收。(此脚本包含在我index.html
的窗口中加载的文件中)。
这是我试图做的:
// main.js submenu
{
'label': 'Open',
click() {
dialog.showOpenDialog({properties: ['openfile']}).then(result => {
win.webContents.send('open', result.filePaths[0])
})
}
}
// index.js
const {ipcRenderer} = require('electron')
ipcRenderer.on('open', (event, file) => {
console.print(file)
console.log('Recieved')
})
但是,这似乎不起作用。
解决方案
推荐阅读
- jasper-reports - 如何使用表格组件在 Jaspersoft Studio 中打印行而不拆分页面?
- jupyter-notebook - 在datalab jupyter notebook中加载csv文件
- python - 在 ndarray.reshape 之后保持数组长度
- spring-boot - 使用 spring-boot-maven-plugin 生成多个可运行的 JAR
- ios - 是否可以使用 Alamofire swift 在 api 命中时将 Array 和 Dictionary 都发送到参数中?
- api - 在邮递员中使用 PUT 请求更新环境时遇到问题
- amazon-web-services - 如何找出 s3 存储中文件的创建日期?
- jenkins - 如何让詹金斯从机在特定的工作区目录中工作
- javascript - 如何使用 curl 关闭电脑
- facebook - SwiftUI 在通过 Facebook 登录进行身份验证后导航到下一个视图