MacOS Dock

Electron有API来配置macOS Dock中的应用程序图标。 A macOS-only API exists to create a custom dock menu, but Electron also uses the app's dock icon to implement cross-platform features like recent documents and application progress.

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

Terminal.app 的 Dock 菜单:

Dock Menu

若要设置自定义的dock菜单, 可以使用 app.dock.setMenu API, 它仅在 macOS 上可用:

  1. const { app, Menu } = require('electron')
  2. const dockMenu = Menu.buildFromTemplate([
  3. {
  4. label: 'New Window',
  5. click () { console.log('New Window') }
  6. }, {
  7. label: 'New Window with Settings',
  8. submenu: [
  9. { label: 'Basic' },
  10. { label: 'Pro' }
  11. ]
  12. },
  13. { label: 'New Command...' }
  14. ])
  15. app.dock.setMenu(dockMenu)