官术网_书友最值得收藏!

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 t hese 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.

主站蜘蛛池模板: 大余县| 桂林市| 永寿县| 闽清县| 临江市| 巴马| 手游| 平安县| 高州市| 德州市| 定兴县| 黎平县| 石城县| 清河县| 横山县| 洛宁县| 宝丰县| 曲周县| 临颍县| 游戏| 英吉沙县| 防城港市| 紫阳县| 积石山| 江陵县| 巩留县| 平邑县| 云阳县| 彰化市| 大石桥市| 英山县| 达州市| 靖远县| 古田县| 江油市| 望城县| 宜宾市| 改则县| 乌拉特中旗| 甘洛县| 崇阳县|