Skip to content

Commit

Permalink
修复 MacOS 下点击 dock 右键菜单的退出按钮时,程序没有退出的问题(#1923
Browse files Browse the repository at this point in the history
  • Loading branch information
lyswhut committed Jun 3, 2024
1 parent b7bb21f commit 69ba619
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 19 deletions.
8 changes: 5 additions & 3 deletions src/main/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { URL_SCHEME_RXP } from '@common/constants'
import { getTheme, initHotKey, initSetting, parseEnvParams } from './utils'
import { navigationUrlWhiteList } from '@common/config'
import defaultSetting from '@common/defaultSetting'
import { closeWindow, isExistWindow as isExistMainWindow, showWindow as showMainWindow } from './modules/winMain'
import { isExistWindow as isExistMainWindow, showWindow as showMainWindow } from './modules/winMain'
import { createAppEvent, createDislikeEvent, createListEvent } from '@main/event'
import { isMac, log } from '@common/utils'
import createWorkers from './worker'
Expand Down Expand Up @@ -158,6 +158,9 @@ export const listenerAppEvent = (startApp: () => void) => {
}
})

app.on('before-quit', () => {
global.lx.isSkipTrayQuit = true
})
app.on('window-all-closed', () => {
if (isMac) return

Expand Down Expand Up @@ -209,7 +212,6 @@ export const initAppSetting = async() => {
if (!global.lx) {
const config = await initHotKey()
global.lx = {
isTrafficLightClose: false,
isSkipTrayQuit: false,
// mainWindowClosed: true,
event_app: createAppEvent(),
Expand Down Expand Up @@ -275,5 +277,5 @@ export const initAppSetting = async() => {

export const quitApp = () => {
global.lx.isSkipTrayQuit = true
closeWindow()
app.quit()
}
16 changes: 6 additions & 10 deletions src/main/modules/winMain/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,15 @@ const winEvent = () => {
if (!browserWindow) return

browserWindow.on('close', event => {
if (
global.lx.appSetting['tray.enable'] &&
(global.lx.isTrafficLightClose || (isWin && !global.lx.isSkipTrayQuit))
) {
global.lx.isTrafficLightClose &&= false
event.preventDefault()
browserWindow!.hide()
if (global.lx.isSkipTrayQuit || !global.lx.appSetting['tray.enable']) {
browserWindow!.setProgressBar(-1)
// global.lx.mainWindowClosed = true
global.lx.event_app.main_window_close()
return
}

browserWindow!.setProgressBar(-1)
// global.lx.mainWindowClosed = true
global.lx.event_app.main_window_close()
event.preventDefault()
browserWindow!.hide()
})

browserWindow.on('closed', () => {
Expand Down
1 change: 0 additions & 1 deletion src/main/modules/winMain/rendererEvent/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ export default () => {
app.exit(0)
return
}
global.lx.isTrafficLightClose = true
closeWindow()
})
// 全屏
Expand Down
4 changes: 0 additions & 4 deletions src/main/types/app.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ interface Lx {
config: LX.HotKeyConfigAll
state: LX.HotKeyState
}
/**
* 是否红绿灯关闭
*/
isTrafficLightClose: boolean
/**
* 是否跳过托盘退出
*/
Expand Down
5 changes: 4 additions & 1 deletion src/renderer/components/layout/PactModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,10 @@ export default {
}, 2e3)
},
handleClose(isExit) {
if (isExit) { quitApp(true); return }
if (isExit) {
quitApp(true)
return
}
isShowPact.value = false
},
openUrl(url) {
Expand Down

0 comments on commit 69ba619

Please sign in to comment.