electron.ipcMain的怪异行为
electron.ipcMain的怪异行为
这比电子问题更像是JavaScript。
我有以下代码:
var electron = require("electron")
var registerTestHandler = function(onFn) {
onFn("test", console.log)
}
electron.app.whenReady()
.then(function() {
registerTestHandler(electron.ipcMain.on)
})
运行应用程序会引发以下错误:
(node:14139) UnhandledPromiseRejectionWarning: TypeError: Cannot read property '_events' of undefined
at _addListener (events.js:228:19)
at addListener (events.js:284:10)
at registerTestHandler (/Users/marco/Desktop/electron-ipc-test/index.js:4:2)
at /Users/marco/Desktop/electron-ipc-test/index.js:9:2
(node:14139) UnhandledPromiseRejectionWarning: TypeError: Cannot read property '_events' of undefined
at _addListener (events.js:228:19)
at addListener (events.js:284:10)
at registerTestHandler (/Users/marco/Desktop/electron-ipc-test/index.js:4:2)
at /Users/marco/Desktop/electron-ipc-test/index.js:9:2
(node:14139) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:14139) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:14139) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:14139) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
现在将代码更改为:
var electron = require("electron")
var registerTestHandler = function(ipc) {
ipc.on("test", console.log)
}
electron.app.whenReady()
.then(function() {
registerTestHandler(electron.ipcMain)
})
而且效果很好!
我认为这与电子无关,而与javascript有关。
但是我无法解释为什么会这样。
有人有想法吗?
回答如下:我在电子github页面上打开了issue,并得到以下解释:
这只是javascript的工作方式,当您从ipcMain中剥离on方法时,将来在调用该方法时将删除此范围。即,如果您将其明确绑定到ipcMain,它将可以正常工作
最新文章
- matlab stats里的f值,MATLAB 回归分析regress,nlinfit,stepwise函数
- oracle中 rownum和rowid的用法
- 林达华博士对数学的见解
- 大型高并发高负载网站的系统架构[转载]
- 我也来说非诚勿扰
- #includelt;和#include
- 哀悼日设置网站主题为黑白主题
- skipped: maximum number of running instances reached (1)
- php开源cms系统比较好,最受欢迎免费开源CMS建站系统排行榜
- VSS使用技巧
- ext4 笔记一(与ext3比较)
- Linux中EXT3与EXT4的区别!
- 线性内插interp1函数用法
- 这些响应式网页测试工具确保你的设计万无一失
- matlab快速入门(1):输入命令
- 统计学,机器学习,深度学习,数据挖掘的联系
- 在window下查看占用tomcat进程,杀死进程并启用tomcat