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

  • Electron Projects
  • Denys Vuika
  • 310字
  • 2021-06-24 12:14:35

Integrating the application menu

As you already know, your application is essentially an HTML5 stack running inside Chromium, and Electron provides all necessary integration with the underlying operating system, whether that's macOS, Windows, or Linux.

The concept of application menus is slightly different across platforms. macOS, for instance, provides a single application menu that reflects the active application and displays the corresponding menu items. The Windows system tends to provide a separate menu for each instance of the application window. Finally, Linux systems usually vary based on the window manager's implementations.

Handling every case would be quite cumbersome for developers; that is why the Electron framework provides a unified interface for building application menus from the JSON definition and takes care of integration details.

Let's take a macOS application menu as an example. As soon as you launch your application, Electron provides a set of predefined menu items. For development, one of the most popular menu items is View as it provides access to application reloading and Chrome Developer Tools:

To see the Developer Tools in action, run the application with npm start and click the View | Toggle Developer Tools menu item.

Note that you instantly get access to the whole set of debugging capabilities for the running application. Later on, you are probably going to use this feature a lot during development. In the following screenshot, you can see what the Chrome Developer Tools look like when you've invoked the menu item:

Now, let's see what it takes to create such menus from within application code. We are going to perform the following actions with the system menu component:

  • Create a custom menu item
  • Define the roles menu item
  • Provide menu separators
  • Support keyboard accelerators
  • Support platform-specific menus

The first thing we need to address is how to create a custom menu item and render it at runtime.

主站蜘蛛池模板: 邢台县| 泸州市| 盐边县| 辉南县| 永顺县| 梧州市| 丘北县| 渭源县| 康定县| 同仁县| 甘肃省| 大邑县| 南雄市| 海盐县| 林周县| 百色市| 琼海市| 英吉沙县| 无为县| 安图县| 武陟县| 绥芬河市| 颍上县| 扎兰屯市| 麻阳| 阳谷县| 北辰区| 广宁县| 石家庄市| 中江县| 金山区| 进贤县| 麻城市| 西吉县| 上饶县| 丹凤县| 肇州县| 招远市| 增城市| 彝良县| 历史|