Electron 如何在主进程中创建菜单?

Electron How to create menus in the main process?

Electron 文档仅讨论在渲染器进程中创建菜单。由于应用程序菜单栏(至少在我的情况下)对于我的应用程序来说是静态的,因此最好从主进程创建一次。

有办法吗?

实际上,the documentation 说它被设计用于 Main 进程,尽管您可以在带有 remote 模块的 Renderer 中使用它:

This module is a main process module which can be used in a render process via the remote module.

所以,无论你有主进程,你只需要做:

const electron = require('electron');
const Menu = electron.Menu;

mainWindow = new BrowserWindow({width: 800, height: 600});

var menu = new Menu();

// Prepare your menu's content ...

Menu.setApplicationMenu(menu);