electron:在简单的hello world应用程序中,无法查看默认菜单栏

electron:在简单的hello world应用程序中,无法查看默认菜单栏,electron,Electron,我对electron还不熟悉,正在尝试运行简单的hello world。 在那个“Electron”应用程序中,它的菜单栏应该显示为一个普通的应用程序,带有通用选项,如编辑、查看、窗口和帮助。但我看不见。我的操作系统是macOS High Sierra 我从下面的链接中获取了简单的hello world代码。 有人能帮忙吗?教程中显示的菜单适用于windows系统。如果未使用menu.setApplicationMenu(菜单)设置菜单,则显示默认菜单。将菜单设置为macOS上的应用程序菜单

我对electron还不熟悉,正在尝试运行简单的hello world。 在那个“Electron”应用程序中,它的菜单栏应该显示为一个普通的应用程序,带有通用选项,如编辑、查看、窗口和帮助。但我看不见。我的操作系统是macOS High Sierra

我从下面的链接中获取了简单的hello world代码。


有人能帮忙吗?

教程中显示的菜单适用于windows系统。如果未使用menu.setApplicationMenu(菜单)设置菜单,则显示默认菜单。将菜单设置为macOS上的应用程序菜单。在Windows和Linux上,菜单将设置为每个窗口的顶部菜单。。如果要显示默认菜单,请使用以下命令。 请使用链接作为参考

const { app, Menu } = require('electron')

const template = [
  // { role: 'appMenu' }
  ...(process.platform === 'darwin' ? [{
    label: app.getName(),
    submenu: [
      { role: 'about' },
      { type: 'separator' },
      { role: 'services' },
      { type: 'separator' },
      { role: 'hide' },
      { role: 'hideothers' },
      { role: 'unhide' },
      { type: 'separator' },
      { role: 'quit' }
    ]
  }] : []),
  // { role: 'fileMenu' }
  {
    label: 'File',
    submenu: [
      isMac ? { role: 'close' } : { role: 'quit' }
    ]
  },
  // { role: 'editMenu' }
  {
    label: 'Edit',
    submenu: [
      { role: 'undo' },
      { role: 'redo' },
      { type: 'separator' },
      { role: 'cut' },
      { role: 'copy' },
      { role: 'paste' },
      ...(isMac ? [
        { role: 'pasteAndMatchStyle' },
        { role: 'delete' },
        { role: 'selectAll' },
        { type: 'separator' },
        {
          label: 'Speech',
          submenu: [
            { role: 'startspeaking' },
            { role: 'stopspeaking' }
          ]
        }
      ] : [
        { role: 'delete' },
        { type: 'separator' },
        { role: 'selectAll' }
      ])
    ]
  },
  // { role: 'viewMenu' }
  {
    label: 'View',
    submenu: [
      { role: 'reload' },
      { role: 'forcereload' },
      { role: 'toggledevtools' },
      { type: 'separator' },
      { role: 'resetzoom' },
      { role: 'zoomin' },
      { role: 'zoomout' },
      { type: 'separator' },
      { role: 'togglefullscreen' }
    ]
  },
  // { role: 'windowMenu' }
  {
    label: 'Window',
    submenu: [
      { role: 'minimize' },
      { role: 'zoom' },
      ...(isMac ? [
        { type: 'separator' },
        { role: 'front' },
        { type: 'separator' },
        { role: 'window' }
      ] : [
        { role: 'close' }
      ])
    ]
  },
  {
    role: 'help',
    submenu: [
      {
        label: 'Learn More',
        click () { require('electron').shell.openExternalSync('https://electronjs.org') }
      }
    ]
  }
]

const menu = Menu.buildFromTemplate(template)
Menu.setApplicationMenu(menu)
为我添加此工作
常数{isMac}=电子

本例中的
isMac
是什么?对我来说,
undefined
(我使用5.0.0,并在自述文件中使用默认模板示例)尝试注释该行,或者使用process.platform==“darwin”,我只是修复了从electron导入“isMac”的问题。