Passing Data to Windows in Electron

前端 未结 2 1264
挽巷
挽巷 2021-02-01 01:40

I\'m learning Electron and working with multiple windows and IPC. In my main script I have the following:

var storeWindow = new BrowserWindow({
  width: 400,
  h         


        
2条回答
  •  南方客
    南方客 (楼主)
    2021-02-01 01:49

    To send events to particular window you can use webContents.send(EVENT_NAME, ARGS) (see docs). webContents is a property of a window instance:

    // main process
    storeWindow.webContents.send('store-data', store);
    

    To listen for this event being sent, you need a listener in a window process (renderer):

    // renderer process
    var ipcRenderer = require('electron').ipcRenderer;
    ipcRenderer.on('store-data', function (event,store) {
        console.log(store);
    });
    

提交回复
热议问题