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

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.

主站蜘蛛池模板: 正定县| 兰溪市| 安溪县| 开阳县| 安仁县| 孝感市| 钟祥市| 清原| 扎兰屯市| 南木林县| 鄂尔多斯市| 海林市| 象山县| 资中县| 城固县| 永康市| 淮滨县| 阿克陶县| 上蔡县| 汕尾市| 嵩明县| 二连浩特市| 湘阴县| 秦安县| 获嘉县| 修水县| 保山市| 巴林左旗| 铅山县| 确山县| 寿光市| 馆陶县| 同江市| 策勒县| 崇州市| 兴业县| 涟源市| 新密市| 漠河县| 大邑县| 从江县|