This commit is contained in:
xuncha
2026-03-16 16:48:01 +08:00
parent 7e05909404
commit bf48e865ac
6 changed files with 414 additions and 3 deletions

View File

@@ -97,6 +97,7 @@ let mainWindowReady = false
let shouldShowMain = true
let isAppQuitting = false
let tray: Tray | null = null
let isClosePromptVisible = false
// 更新下载状态管理Issue #294 修复)
let isDownloadInProgress = false
@@ -354,10 +355,14 @@ function createWindow(options: { autoShow?: boolean } = {}) {
})
win.on('close', (e) => {
if (isAppQuitting) return
// 关闭主窗口时隐藏到状态栏而不是退出
if (isAppQuitting || win !== mainWindow) return
e.preventDefault()
win.hide()
if (isClosePromptVisible) return
isClosePromptVisible = true
win.webContents.send('window:confirmCloseRequested', {
canMinimizeToTray: Boolean(tray)
})
})
win.on('closed', () => {
@@ -365,6 +370,7 @@ function createWindow(options: { autoShow?: boolean } = {}) {
mainWindow = null
mainWindowReady = false
isClosePromptVisible = false
if (process.platform !== 'darwin' && !isAppQuitting) {
destroyNotificationWindow()
@@ -1154,6 +1160,33 @@ function registerIpcHandlers() {
BrowserWindow.fromWebContents(event.sender)?.close()
})
ipcMain.handle('window:respondCloseConfirm', async (_event, action: 'tray' | 'quit' | 'cancel') => {
if (!mainWindow || mainWindow.isDestroyed()) {
isClosePromptVisible = false
return false
}
try {
if (action === 'tray') {
if (tray) {
mainWindow.hide()
return true
}
return false
}
if (action === 'quit') {
isAppQuitting = true
app.quit()
return true
}
return true
} finally {
isClosePromptVisible = false
}
})
// 更新窗口控件主题色
ipcMain.on('window:setTitleBarOverlay', (event, options: { symbolColor: string }) => {
const win = BrowserWindow.fromWebContents(event.sender)