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

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.

主站蜘蛛池模板: 九江县| 鄂温| 富阳市| 射洪县| 云梦县| 鞍山市| 孝义市| 荥经县| 兰溪市| 新竹市| 通化市| 桐城市| 科技| 白河县| 唐河县| 和平区| 镇宁| 高雄市| 中阳县| 怀远县| 木兰县| 满洲里市| 屏南县| 郁南县| 永昌县| 申扎县| 寿阳县| 芮城县| 永川市| 体育| 思南县| 左贡县| 阜阳市| 姚安县| 确山县| 金华市| 尉犁县| 钦州市| 上蔡县| 灵武市| 湘乡市|