From 0ef108df4ccd017f1f23b33d2fe7ce5d59c055ea Mon Sep 17 00:00:00 2001 From: TestGifts Date: Sun, 31 Jan 2021 18:05:37 +0800 Subject: [PATCH] feat(electron): Add close pop-up confirmation (#157) * Update ipcMain.js Add close pop-up confirmation * Update ipcMain.js Judging MacOS --- src/electron/ipcMain.js | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/src/electron/ipcMain.js b/src/electron/ipcMain.js index 5ab4f57..75e15b6 100644 --- a/src/electron/ipcMain.js +++ b/src/electron/ipcMain.js @@ -24,12 +24,34 @@ export function initIpcMain(win, store) { event.returnValue = null; }); }); - - ipcMain.on("close", () => { - win.hide(); - // win.close(); - // app.quit(); + + ipcMain.on('close', (e) => { + if (process.platform == 'darwin') { + //判断mac + win.hide(); + }) + e.preventDefault()//阻止默认行为 + dialog.showMessageBox({ + type: 'info', + title: 'Information', + cancelId:2, + defaultId: 0, + message: '确定要关闭吗?', + buttons: ['最小化','直接退出'] + }).then(result => { + if (result.response == 0) { + e.preventDefault(); //阻止默认行为 + win.minimize(); //调用 最小化实例方法 + } else if(result.response == 1) { + win = null; + //app.quit(); + app.exit(); //exit()直接关闭客户端,不会执行quit(); + } + }).catch(err => { + console.log(err) + }) }); + ipcMain.on("minimize", () => { win.minimize();