- 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.
- Go Web編程
- Spring 5.0 By Example
- 編寫高質量代碼:改善Python程序的91個建議
- x86匯編語言:從實模式到保護模式(第2版)
- The React Workshop
- SQL語言從入門到精通
- Learning Selenium Testing Tools(Third Edition)
- SQL Server從入門到精通(第3版)
- Test-Driven Development with Django
- The Professional ScrumMaster’s Handbook
- Vue.js 2 Web Development Projects
- Python自然語言理解:自然語言理解系統開發與應用實戰
- MongoDB Cookbook(Second Edition)
- Kotlin進階實戰
- Java EE項目應用開發