no message

This commit is contained in:
kuaifan 2022-04-01 10:13:41 +08:00
parent 38c1a768fc
commit e0a3259765
3 changed files with 36 additions and 29 deletions

19
electron/electron.js vendored
View File

@ -59,7 +59,15 @@ function createMainWindow() {
mainWindow.on('close', event => { mainWindow.on('close', event => {
if (!willQuitApp) { 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 => { browser.on('close', event => {
utils.onBeforeUnload(event) utils.onBeforeUnload(event).then(() => {
event.sender.destroy()
})
}) })
browser.on('closed', () => { browser.on('closed', () => {
@ -149,10 +159,13 @@ if (!getTheLock) {
createMainWindow() createMainWindow()
// 创建托盘 // 创建托盘
if (['darwin', 'win32'].includes(process.platform)) { 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', () => { mainTray.on('click', () => {
utils.setShowWindow(mainWindow) utils.setShowWindow(mainWindow)
}) })
mainTray.on('double-click', () => {
utils.setShowWindow(mainWindow)
})
mainTray.setToolTip(config.name) mainTray.setToolTip(config.name)
if (process.platform === 'win32') { if (process.platform === 'win32') {
const trayMenu = Menu.buildFromTemplate([{ const trayMenu = Menu.buildFromTemplate([{

View File

@ -47,6 +47,10 @@
"fs-extra": "^10.0.1", "fs-extra": "^10.0.1",
"pdf-lib": "^1.17.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": { "build": {
"appId": "com.dootask.task", "appId": "com.dootask.task",
"artifactName": "${productName}-v${version}-${os}-${arch}.${ext}", "artifactName": "${productName}-v${version}-${os}-${arch}.${ext}",
@ -65,7 +69,6 @@
"afterSign": "./notarize.js", "afterSign": "./notarize.js",
"mac": { "mac": {
"icon": "../resources/assets/statics/public/images/logo-app.png", "icon": "../resources/assets/statics/public/images/logo-app.png",
"trayIcon": "../resources/assets/statics/public/images/tray/logo-trayTemplate.png",
"entitlements": "entitlements.plist", "entitlements": "entitlements.plist",
"entitlementsInherit": "entitlements.plist", "entitlementsInherit": "entitlements.plist",
"category": "public.app-category.productivity", "category": "public.app-category.productivity",

17
electron/utils.js vendored
View File

@ -290,33 +290,24 @@ module.exports = {
* @param app * @param app
*/ */
onBeforeUnload(event, app) { onBeforeUnload(event, app) {
return new Promise(resolve => {
const sender = event.sender const sender = event.sender
const contents = sender.webContents const contents = sender.webContents
if (contents != null) { if (contents != null) {
const destroy = () => {
if (typeof app === "undefined") {
sender.destroy()
} else {
if (['darwin', 'win32'].includes(process.platform)) {
app.hide()
} else {
app.quit()
}
}
}
contents.executeJavaScript('if(typeof window.__onBeforeUnload === \'function\'){window.__onBeforeUnload()}', true).then(options => { contents.executeJavaScript('if(typeof window.__onBeforeUnload === \'function\'){window.__onBeforeUnload()}', true).then(options => {
if (this.isJson(options)) { if (this.isJson(options)) {
let choice = dialog.showMessageBoxSync(sender, options) let choice = dialog.showMessageBoxSync(sender, options)
if (choice === 1) { if (choice === 1) {
contents.executeJavaScript('if(typeof window.__removeBeforeUnload === \'function\'){window.__removeBeforeUnload()}', true).catch(() => {}); contents.executeJavaScript('if(typeof window.__removeBeforeUnload === \'function\'){window.__removeBeforeUnload()}', true).catch(() => {});
destroy() resolve()
} }
} else if (options !== true) { } else if (options !== true) {
destroy() resolve()
} }
}) })
event.preventDefault() event.preventDefault()
} }
})
}, },
/** /**