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

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.

主站蜘蛛池模板: 长沙县| 潜江市| 鱼台县| 大新县| 娄底市| 师宗县| 岑溪市| 蕲春县| 卓资县| 安溪县| 建德市| 图木舒克市| 如东县| 彩票| 渑池县| 玛沁县| 科技| 通城县| 禹州市| 安陆市| 凤台县| 辰溪县| 双牌县| 明光市| 孟津县| 桂阳县| 余干县| 来凤县| 日照市| 射阳县| 济宁市| 清水河县| 蓬安县| 河北省| 通海县| 东安县| 磴口县| 青河县| 西乌| 靖州| 陇南市|