Dock (macOS)

    The custom dock is commonly used to add shortcuts to tasks the user wouldn’t want to open the whole app window for.

    Dock menu of Terminal.app:

    To set your custom dock menu, you need to use the app.dock.setMenu API, which is only available on macOS.

    Starting with a working application from the , update the file with the following lines:

    • index.html
    • main.js
    1. const { app, BrowserWindow, Menu } = require('electron')
    2. function createWindow () {
    3. const win = new BrowserWindow({
    4. width: 800,
    5. height: 600,
    6. })
    7. win.loadFile('index.html')
    8. }
    9. {
    10. click () { console.log('New Window') }
    11. }, {
    12. label: 'New Window with Settings',
    13. submenu: [
    14. { label: 'Basic' },
    15. { label: 'Pro' }
    16. ]
    17. },
    18. { label: 'New Command...' }
    19. ])
    20. app.whenReady().then(() => {
    21. }
    22. }).then(createWindow)
    23. app.on('window-all-closed', () => {
    24. if (process.platform !== 'darwin') {
    25. app.quit()
    26. }
    27. })
    28. app.on('activate', () => {
    29. if (BrowserWindow.getAllWindows().length === 0) {
    30. createWindow()
    31. }

    After launching the Electron application, right click the application icon. You should see the custom menu you just defined: