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

  • Electron Projects
  • Denys Vuika
  • 253字
  • 2021-06-24 12:14:37

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.

主站蜘蛛池模板: 平乐县| 南充市| 福清市| 凤城市| 如皋市| 岳阳市| 边坝县| 阿图什市| 内黄县| 华容县| 吴旗县| 麻栗坡县| 三原县| 江安县| 高台县| 商南县| 桑植县| 昌邑市| 渝北区| 万荣县| 伊金霍洛旗| 静乐县| 曲靖市| 祁东县| 乾安县| 黄大仙区| 山丹县| 当涂县| 射洪县| 建平县| 康定县| 虹口区| 维西| 沈丘县| 江安县| 临西县| 眉山市| 裕民县| 博兴县| 台东市| 常州市|