diff --git a/docs/fiddles/features/macos-dock-menu/index.html b/docs/fiddles/features/macos-dock-menu/index.html index a3855d2640..02eb6e015a 100644 --- a/docs/fiddles/features/macos-dock-menu/index.html +++ b/docs/fiddles/features/macos-dock-menu/index.html @@ -7,10 +7,6 @@

Hello World!

-

- We are using node , - Chrome , - and Electron . -

+

Right click the dock icon to see the custom menu options.

diff --git a/docs/fiddles/features/macos-dock-menu/main.js b/docs/fiddles/features/macos-dock-menu/main.js index f57caf628c..f7f86a2361 100644 --- a/docs/fiddles/features/macos-dock-menu/main.js +++ b/docs/fiddles/features/macos-dock-menu/main.js @@ -4,9 +4,6 @@ function createWindow () { const win = new BrowserWindow({ width: 800, height: 600, - webPreferences: { - nodeIntegration: true - } }) win.loadFile('index.html') @@ -27,7 +24,9 @@ const dockMenu = Menu.buildFromTemplate([ ]) app.whenReady().then(() => { - app.dock.setMenu(dockMenu) + if (process.platform === 'darwin') { + app.dock.setMenu(dockMenu) + } }).then(createWindow) app.on('window-all-closed', () => { diff --git a/docs/tutorial/macos-dock.md b/docs/tutorial/macos-dock.md index b61a0291da..b5527a4956 100644 --- a/docs/tutorial/macos-dock.md +++ b/docs/tutorial/macos-dock.md @@ -1,6 +1,4 @@ -# macOS Dock - -## Overview +# Configuring the macOS Dock Electron has APIs to configure the app's icon in the macOS Dock. A macOS-only API exists to create a custom dock menu, but Electron also uses the app dock @@ -25,7 +23,16 @@ Starting with a working application from the following lines: ```javascript fiddle='docs/fiddles/features/macos-dock-menu' -const { app, Menu } = require('electron') +const { app, BrowserWindow, Menu } = require('electron') + +function createWindow () { + const win = new BrowserWindow({ + width: 800, + height: 600, + }) + + win.loadFile('index.html') +} const dockMenu = Menu.buildFromTemplate([ { @@ -42,8 +49,23 @@ const dockMenu = Menu.buildFromTemplate([ ]) app.whenReady().then(() => { - app.dock.setMenu(dockMenu) + if (process.platform === 'darwin') { + app.dock.setMenu(dockMenu) + } +}).then(createWindow) + +app.on('window-all-closed', () => { + if (process.platform !== 'darwin') { + app.quit() + } }) + +app.on('activate', () => { + if (BrowserWindow.getAllWindows().length === 0) { + createWindow() + } +}) + ``` After launching the Electron application, right click the application icon.