Electron - IPC 模块不从渲染器向 main 发送数据

Electron - IPC module not sending data to main from renderer

我是 Electron 的新手,我正在尝试使用 IPC 模块将变量从渲染器进程文件发送到主程序。我在 Devtron 面板中看到 IPC 消息正在从渲染器发出,但它没有显示在 main.js 中收到的迹象。我怀疑问题可能与文件如何链接在一起有关;我从 index.html 中的链接脚本标记调用渲染器文件,但希望渲染器文件(在本例中为 keycapture.js)直接发送到 main.js,但我没有确保这就是它的工作原理。

以下是提供和发送 IPC 消息的代码段:

main.js:

app.on('ready',function(){

  //Set up a listener for what I've done in keycapture (in the renderer process)

      //???
  ipc.on('invokeAction', function(event, args){
    console.log("RECEIVED IPC IN MAIN!")
    var hotkey = args;
    console.log(hotkey);
    //var result = processData(data);
    //event.sender.send('actionReply', result);
    //Alright, time to test and troubleshoot.  
  });

keycapture.js(链接自 index.html,其中 main.js 加载):

function keyCancel(ev){
        /*******
        Use IPC to send the data back to Main to pass on to the local appData file

        Modify the below code to fit with what I'm trying to do.
        *******/

        ipcRenderer.send('invokeAction', hotkey);
        //Remove focus from the input field
        $(input).blur();
         return;
      }

所以我认为问题是因为我正在使用 VSCode,所以我必须首先设置调试启动选项,以便它识别调试会话而不是节点会话,而是电子会话,这会导致 VScode 在调试器中识别出 electron 的子方法(如 app、BrowserWindow 等)。如果不这样做,它就不会寻找那些并抛出未定义的错误。