【发布时间】:2020-07-27 06:34:09
【问题描述】:
最近我一直在开发一个加密文件的 Windows 应用程序(使用 Electronjs)。我想要它,这样当我按下渲染器中的第一个按钮时,它会发送到主进程,要求它打开打开文件对话框。我试过这段代码。
renderer.js
firstButton.addEventListener("click", openFile)
function openFile() {
ipc.send('open-the-open-dialogue');
}
ipc.on('file-picked', function(event, arg) {
console.log(arg);
}
main.js
ipc.on('open-the-open-dialogue',
function () {
var filenames = dialog.showOpenDialogSync({ properties: ['openFile'] });
if(!filenames) {
dialog.showErrorBox("ERROR!", "You didn't pick a file to encrypt.")
}
event.reply('file-opened', filenames[0]);
}
);
当我尝试这段代码时,它出现了一个错误,指出事件未定义。那我做错了什么?
【问题讨论】:
标签: javascript electron ipc