From 28143774c15ee2f34314605c636c6015a6a76b66 Mon Sep 17 00:00:00 2001 From: Matthijs Groen Date: Thu, 6 May 2021 10:19:06 +0200 Subject: [PATCH] docs: menu must be added on whenReady (#28958) --- docs/tutorial/recent-documents.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/docs/tutorial/recent-documents.md b/docs/tutorial/recent-documents.md index e23df89834e..c26f7964cc3 100644 --- a/docs/tutorial/recent-documents.md +++ b/docs/tutorial/recent-documents.md @@ -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