Why does my Electron app quit when closing a Renderer window?

我怕爱的太早我们不能终老 提交于 2019-12-23 21:37:36

问题


I'm testing on Windows. The app sets up a Tray menu on 'ready', with an 'About' label. When clicked, it shows a BrowserWindow:

 var aboutBox = new BrowserWindow({
        width: 460, height: 176, useContentSize: true,
        icon: iconImg,
        maximizable: false, fullscreenable: false, resizable: false, minimizable: false
    });

and then, when the user clicks on OK, closing it with:

const remote = require('electron').remote;
remote.getCurrentWindow().close();

causes the app to exit.

Why?


回答1:


In your main.js you could have this code:

// Quit when all windows are closed.

  app.on('window-all-closed', function () {
  // On OS X 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()
  }
})

So because you close the unique windows this event it's emitted and app is closed.

EDIT This behavior is also default in Electron, so to avoid closing app closing the main window add this line:

app.on('window-all-closed', e => e.preventDefault() )


来源:https://stackoverflow.com/questions/46596493/why-does-my-electron-app-quit-when-closing-a-renderer-window

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!