Electron - IPC模块不从渲染器

时间:2018-04-30 00:17:46

标签: javascript electron ipc

我是Electron的新手,我正在尝试使用IPC模块将渲染器进程文件中的变量发送到main。我在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;
      }

1 个答案:

答案 0 :(得分:0)

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

相关问题