mirror of
https://github.com/electron/electron.git
synced 2026-04-10 03:01:51 -04:00
docs: menu must be added on whenReady (#29043)
* Add that that menu must be added on whenReady When an application menu is added before 'whenReady' all items seem to work except 'recent documents' This causes the issue listed here: https://github.com/electron/electron/issues/17388 * Make example more complete * Remove semicolons * Update docs/tutorial/recent-documents.md Co-authored-by: Erick Zhao <erick@hotmail.ca> Co-authored-by: Matthijs Groen <matthijs.groen@gmail.com> Co-authored-by: Erick Zhao <erick@hotmail.ca>
This commit is contained in:
@@ -83,6 +83,22 @@ following code snippet to your menu template:
|
||||
}
|
||||
```
|
||||
|
||||
Make sure the application menu is added after the [`'ready'`](../api/app.md#event-ready)
|
||||
event and not before, or the menu item will be disabled:
|
||||
|
||||
```javascript
|
||||
const { app, Menu } = require('electron')
|
||||
|
||||
const template = [
|
||||
// Menu template here
|
||||
]
|
||||
const menu = Menu.buildFromTemplate(template)
|
||||
|
||||
app.whenReady().then(() => {
|
||||
Menu.setApplicationMenu(menu)
|
||||
})
|
||||
```
|
||||
|
||||
![macOS Recent Documents menu item][menu-item-image]
|
||||
|
||||
When a file is requested from the recent documents menu, the `open-file` event
|
||||
|
||||
Reference in New Issue
Block a user