22
33> Create native application menus and context menus.
44
5- This module is a main process module which can be used in a render process via
6- the ` remote ` module.
7-
8- Each menu consists of multiple [ menu items] ( menu-item.md ) and each menu item can
9- have a submenu.
10-
11- ## Process Difference Notice
12-
13- Due to Menu and MenuItem can be used in two processes, the way they are included is slightly different.
14-
15- ### Main process
16- ```
17- const {Menu, MenuItem} = require('electron');
18- ```
19-
20- ### Render process
21- ```
22- const {remote} = require('electron')
23- const {Menu, MenuItem} = remote;
24- ```
5+ Each ` Menu ` consists of multiple [ ` MenuItem ` ] ( menu-item.md ) s and each ` MenuItem `
6+ can have a submenu.
257
268## Examples
279
10+ The ` Menu ` class is only available in the main process, but you can also use it
11+ in the render process via the [ ` remote ` ] ( remote.md ) module.
12+
2813### Main process
2914
3015An example of creating the application menu in the main process with the
@@ -181,14 +166,14 @@ Menu.setApplicationMenu(menu)
181166### Render process
182167
183168Below is an example of creating a menu dynamically in a web page
184- (render process) by using the [ remote] ( remote.md ) module, and showing it when
169+ (render process) by using the [ ` remote ` ] ( remote.md ) module, and showing it when
185170the user right clicks the page:
186171
187172``` html
188173<!-- index.html -->
189174<script >
190175const {remote } = require (' electron' )
191- const {Menu , MenuItem } = remote;
176+ const {Menu , MenuItem } = remote
192177
193178const menu = new Menu ()
194179menu .append (new MenuItem ({label: ' MenuItem1' , click () { console .log (' item 1 clicked' ) }}))
@@ -202,7 +187,6 @@ window.addEventListener('contextmenu', (e) => {
202187 </script >
203188```
204189
205-
206190## Class: Menu
207191
208192### ` new Menu() `
0 commit comments