Skip to content

Commit

Permalink
no message
Browse files Browse the repository at this point in the history
  • Loading branch information
kuaifan committed Apr 1, 2022
1 parent 38c1a76 commit e0a3259
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 29 deletions.
19 changes: 16 additions & 3 deletions electron/electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
})
}
})
}
Expand Down Expand Up @@ -110,7 +118,9 @@ function createSubWindow(args) {
})

browser.on('close', event => {
utils.onBeforeUnload(event)
utils.onBeforeUnload(event).then(() => {
event.sender.destroy()
})
})

browser.on('closed', () => {
Expand Down Expand Up @@ -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([{
Expand Down
5 changes: 4 additions & 1 deletion electron/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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}",
Expand All @@ -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",
Expand Down
41 changes: 16 additions & 25 deletions electron/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
})
},

/**
Expand Down

0 comments on commit e0a3259

Please sign in to comment.