diff --git a/electron/electron.js b/electron/electron.js index a3c9c1985..11cc3784a 100644 --- a/electron/electron.js +++ b/electron/electron.js @@ -59,7 +59,15 @@ function createMainWindow() { mainWindow.on('close', event => { if (!willQuitApp) { - utils.onBeforeUnload(event, app) + utils.onBeforeUnload(event).then(() => { + if (process.platform === 'win32') { + mainWindow.hide() + } else if (process.platform === 'darwin') { + app.hide() + } else { + app.quit() + } + }) } }) } @@ -110,7 +118,9 @@ function createSubWindow(args) { }) browser.on('close', event => { - utils.onBeforeUnload(event) + utils.onBeforeUnload(event).then(() => { + event.sender.destroy() + }) }) browser.on('closed', () => { @@ -149,10 +159,13 @@ if (!getTheLock) { createMainWindow() // εˆ›ε»Ίζ‰˜η›˜ if (['darwin', 'win32'].includes(process.platform)) { - mainTray = new Tray(process.platform === 'darwin' ? config.build.mac.trayIcon : config.build.win.icon); + mainTray = new Tray(process.platform === 'darwin' ? config.trayIcon.mac : config.trayIcon.win); mainTray.on('click', () => { utils.setShowWindow(mainWindow) }) + mainTray.on('double-click', () => { + utils.setShowWindow(mainWindow) + }) mainTray.setToolTip(config.name) if (process.platform === 'win32') { const trayMenu = Menu.buildFromTemplate([{ diff --git a/electron/package.json b/electron/package.json index 903af8b01..df9a1ecc5 100644 --- a/electron/package.json +++ b/electron/package.json @@ -47,6 +47,10 @@ "fs-extra": "^10.0.1", "pdf-lib": "^1.17.1" }, + "trayIcon": { + "mac": "../resources/assets/statics/public/images/tray/logo-trayTemplate.png", + "win": "../resources/assets/statics/public/images/logo-app.ico" + }, "build": { "appId": "com.dootask.task", "artifactName": "${productName}-v${version}-${os}-${arch}.${ext}", @@ -65,7 +69,6 @@ "afterSign": "./notarize.js", "mac": { "icon": "../resources/assets/statics/public/images/logo-app.png", - "trayIcon": "../resources/assets/statics/public/images/tray/logo-trayTemplate.png", "entitlements": "entitlements.plist", "entitlementsInherit": "entitlements.plist", "category": "public.app-category.productivity", diff --git a/electron/utils.js b/electron/utils.js index 8b5654f81..047bbe726 100644 --- a/electron/utils.js +++ b/electron/utils.js @@ -290,33 +290,24 @@ module.exports = { * @param app */ onBeforeUnload(event, app) { - const sender = event.sender - const contents = sender.webContents - if (contents != null) { - const destroy = () => { - if (typeof app === "undefined") { - sender.destroy() - } else { - if (['darwin', 'win32'].includes(process.platform)) { - app.hide() - } else { - app.quit() + return new Promise(resolve => { + const sender = event.sender + const contents = sender.webContents + if (contents != null) { + contents.executeJavaScript('if(typeof window.__onBeforeUnload === \'function\'){window.__onBeforeUnload()}', true).then(options => { + if (this.isJson(options)) { + let choice = dialog.showMessageBoxSync(sender, options) + if (choice === 1) { + contents.executeJavaScript('if(typeof window.__removeBeforeUnload === \'function\'){window.__removeBeforeUnload()}', true).catch(() => {}); + resolve() + } + } else if (options !== true) { + resolve() } - } + }) + event.preventDefault() } - contents.executeJavaScript('if(typeof window.__onBeforeUnload === \'function\'){window.__onBeforeUnload()}', true).then(options => { - if (this.isJson(options)) { - let choice = dialog.showMessageBoxSync(sender, options) - if (choice === 1) { - contents.executeJavaScript('if(typeof window.__removeBeforeUnload === \'function\'){window.__removeBeforeUnload()}', true).catch(() => {}); - destroy() - } - } else if (options !== true) { - destroy() - } - }) - event.preventDefault() - } + }) }, /**