Editor.Ipc

Methods

Editor.Ipc.cancelRequest (sessionID)

  • sessionID string - Session ID.
    Cancel request sent to main or renderer process.

Editor.Ipc.option (opts)

  • opts object
    • excludeSelf boolean - exclude send ipc message to main process when calling Editor.Ipc.sendToAll.
      Ipc option used in Editor.Ipc.sendToAll.

Editor.Ipc.sendToAll (message[, …args, option])

  • message string - Ipc message.
  • …args … - Whatever arguments the message needs.
  • option object - You can indicate the last argument as an IPC option by Editor.Ipc.option({…}).
    Send message with …args to all opened window and to main process asynchronously.

Editor.Ipc.sendToMain (message[, …args, callback, timeout])

  • message string - Ipc message.
  • …args … - Whatever arguments the message needs.
  • callback function - You can specify a callback function to receive IPC reply at the last or the 2nd last argument.
  • timeout number - You can specify a timeout for the callback at the last argument. If no timeout specified, it will be 5000ms.
    Send message with …args to main process asynchronously. It is possible to add a callback as the last or the 2nd last argument to receive replies from the IPC receiver.

Example:

Send IPC message (main process)

  1. Editor.Ipc.sendToMain('foobar:say-hello', err => {
  2. if ( err.code === 'ETIMEOUT' ) {
  3. console.error('Timeout for ipc message foobar:say-hello');
  4. return;
  5. }
  6. console.log('foobar replied');
  7. });

Receive and Reply IPC message (main process)

  1. require('ipc').on('foobar:say-hello', event => {
  2. event.reply('Hi');
  3. });

Editor.Ipc.sendToMainWin (message[, …args])

  • message string - Ipc message.
  • …args … - Whatever arguments the message needs.

Send message with …args to the main window asynchronously.

Editor.Ipc.sendToPanel (panelID, message[, …args, callback, timeout])

  • panelID string - Panel ID.
  • message string - Ipc message.
  • …args … - Whatever arguments the message needs.
  • callback function - You can specify a callback function to receive IPC reply at the last or the 2nd last argument.
  • timeout number - You can specify a timeout for the callback at the last argument. If no timeout specified, it will be 5000ms.
    Send message with …args to panel defined in renderer process asynchronously. It is possible to add a callback as the last or the 2nd last argument to receive replies from the IPC receiver.

Example:

Send IPC message (main process)

  1. Editor.Ipc.sendToPanel('foobar', 'foobar:say-hello', err => {
  2. if ( err.code === 'ETIMEOUT' ) {
  3. console.error('Timeout for ipc message foobar:say-hello');
  4. return;
  5. }
  6. console.log('foobar replied');
  7. });

Receive and Reply IPC message (renderer process)

  1. Editor.Panel.extend({
  2. messages: {
  3. 'foobar:say-hello' (event) {
  4. event.reply('Hi');
  5. }
  6. }
  7. });

Editor.Ipc.sendToWins (message[, …args])

  • message string - Ipc message.
  • …args … - Whatever arguments the message needs.
    Send message with …args to all opened windows asynchronously. The renderer process can handle it by listening to the message through the Electron.ipcRenderer module.

Example:

Send IPC message (main process)

  1. Editor.Ipc.sendToWins('foobar:say-hello', 'Hello World!');

Receive IPC message (renderer process)

  1. <html>
  2. <body>
  3. <script>
  4. require('ipc').on('foobar:say-hello', (event, text) => {
  5. console.log(text); // Prints "Hello World!"
  6. });
  7. </script>
  8. </body>
  9. </html>