electron开发 - mac关闭和隐藏窗口

针对mac平台的app

let willQuitApp = false;  // 控制退出方式

mainWindow.on('close', (e) => {
    if (willQuitApp) {
      mainWindow = null;
      printWindow = null; // 其他窗口也要会回收
    } else { // mac平台,左上角关闭窗口 = 隐藏窗口
      e.preventDefault();
      mainWindow.hide();
    }
  });

// Quit when all windows are closed.
app.on('window-all-closed', () => {
  // 在 macOS 上,除非用户用 Cmd + Q 确定地退出,
  // 否则绝大部分应用及其菜单栏会保持激活。
  if (process.platform !== 'darwin') {
    app.quit()
  }
});

app.on('before-quit', () => {
  willQuitApp = true
});

posted @ 2020-03-18 11:53  枫叶丶|  阅读(2760)  评论(1编辑  收藏  举报