fix: 修复在macOS m1 中点击全屏幕后,点击关闭后黑屏的问题
This commit is contained in:
parent
6cb3b16451
commit
a0413158c8
@ -13,6 +13,8 @@ import { configManager } from './ConfigManager'
|
|||||||
export class WindowService {
|
export class WindowService {
|
||||||
private static instance: WindowService | null = null
|
private static instance: WindowService | null = null
|
||||||
private mainWindow: BrowserWindow | null = null
|
private mainWindow: BrowserWindow | null = null
|
||||||
|
private isQuitting: boolean = false
|
||||||
|
private wasFullScreen: boolean = false
|
||||||
|
|
||||||
public static getInstance(): WindowService {
|
public static getInstance(): WindowService {
|
||||||
if (!WindowService.instance) {
|
if (!WindowService.instance) {
|
||||||
@ -42,7 +44,7 @@ export class WindowService {
|
|||||||
height: mainWindowState.height,
|
height: mainWindowState.height,
|
||||||
minWidth: 1080,
|
minWidth: 1080,
|
||||||
minHeight: 600,
|
minHeight: 600,
|
||||||
show: true,
|
show: false, // 初始不显示
|
||||||
autoHideMenuBar: true,
|
autoHideMenuBar: true,
|
||||||
transparent: isMac,
|
transparent: isMac,
|
||||||
vibrancy: 'under-window',
|
vibrancy: 'under-window',
|
||||||
@ -118,9 +120,20 @@ export class WindowService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private setupWindowEvents(mainWindow: BrowserWindow) {
|
private setupWindowEvents(mainWindow: BrowserWindow) {
|
||||||
mainWindow.on('ready-to-show', () => {
|
mainWindow.once('ready-to-show', () => {
|
||||||
mainWindow.show()
|
mainWindow.show()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// 处理全屏相关事件
|
||||||
|
mainWindow.on('enter-full-screen', () => {
|
||||||
|
this.wasFullScreen = true
|
||||||
|
mainWindow.webContents.send('fullscreen-status-changed', true)
|
||||||
|
})
|
||||||
|
|
||||||
|
mainWindow.on('leave-full-screen', () => {
|
||||||
|
this.wasFullScreen = false
|
||||||
|
mainWindow.webContents.send('fullscreen-status-changed', false)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
private setupWebContentsHandlers(mainWindow: BrowserWindow) {
|
private setupWebContentsHandlers(mainWindow: BrowserWindow) {
|
||||||
@ -182,6 +195,11 @@ export class WindowService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private setupWindowLifecycleEvents(mainWindow: BrowserWindow) {
|
private setupWindowLifecycleEvents(mainWindow: BrowserWindow) {
|
||||||
|
// 监听应用退出事件
|
||||||
|
app.on('before-quit', () => {
|
||||||
|
this.isQuitting = true
|
||||||
|
})
|
||||||
|
|
||||||
mainWindow.on('close', (event) => {
|
mainWindow.on('close', (event) => {
|
||||||
const notInTray = !configManager.isTray()
|
const notInTray = !configManager.isTray()
|
||||||
|
|
||||||
@ -191,9 +209,15 @@ export class WindowService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Mac
|
// Mac
|
||||||
if (!app.isQuitting) {
|
if (!this.isQuitting) {
|
||||||
event.preventDefault()
|
if (this.wasFullScreen) {
|
||||||
mainWindow.hide()
|
// 如果是全屏状态,直接退出
|
||||||
|
this.isQuitting = true
|
||||||
|
app.quit()
|
||||||
|
} else {
|
||||||
|
event.preventDefault()
|
||||||
|
mainWindow.hide()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user