Sending messages between processes

Let's take a closer look at keyboard handling with our editor. By default, the SimpleMDE component provides support for most common editing shortcuts, such as the following:

  • Cmd + B (Mac) or Ctrl + B (PC) to toggle the bold feature
  • Cmd + H (Mac) or Ctrl + H (PC) to toggle the heading feature
  • Cmd + I (Mac) or Ctrl + I (PC) to toggle the italics feature
Note, however, that these commands are supported by the web component itself, not by the Electron shell. You can find out more about supported keyboard shortcuts at https://github.com/sparksuite/simplemde-markdown-editor#keyboard-shortcuts.

The application menu isn't part of the web page. Therefore, we need a way to handle clicks and let the web page know that something has happened, or to trigger some code in JavaScript.

As you already know, the Electron framework is a combination of Chromium (rendering process) and Node.js (main process). Those processes are running side by side but isolated, and the only way to communicate between both processes is by sending messages.

This is why we are going to build the following data flow. The users of your application should get the Edit menu with the Bold item. Every time the Bold menu item is clicked, the Node.js (main process) handles the keyboard event and sends the message to the web page (rendering process) that the user wants to toggle the Bold feature for. Through JavaScript, the web page invokes the underlying functionality in the markdown editor component it uses.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset