如何退出Mac上的Electron应用程序?

时间:2017-06-01 20:11:52

标签: macos electron

以下是Electron网站(https://electron.atom.io/docs/tutorial/quick-start/)的股票代码:

app.on('window-all-closed', () => {
  if (process.platform !== 'darwin') {
    app.quit()
  }
})

在Mac OS 10.12.4上,当调用上述内容时,它不会关闭应用程序。只有窗口。在条件之上添加app.quit()会关闭应用。他们是否留下了特定于Mac OS X的内容,阻止了应用程序关闭?

1 个答案:

答案 0 :(得分:9)

您需要了解如何阅读代码中的注释。这是您链接的页面的完整摘录:

// Quit when all windows are closed.
app.on('window-all-closed', () => {
  // On macOS it is common for applications and their menu bar
  // to stay active until the user quits explicitly with Cmd + Q
  if (process.platform !== 'darwin') {
    app.quit()
  }
})

if语句上面的两行与if语句相关。这基本上表示我们退出macOS 上的应用,因为这是其他应用中常见的功能。