針對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
});