新增询问窗口

This commit is contained in:
xuncha
2026-03-16 17:21:59 +08:00
parent 999ddaeb9a
commit f2b1b07f58
7 changed files with 206 additions and 17 deletions

View File

@@ -99,6 +99,8 @@ let isAppQuitting = false
let tray: Tray | null = null
let isClosePromptVisible = false
type WindowCloseBehavior = 'ask' | 'tray' | 'quit'
// 更新下载状态管理Issue #294 修复)
let isDownloadInProgress = false
let downloadProgressHandler: ((progress: any) => void) | null = null
@@ -254,6 +256,19 @@ const setupCustomTitleBarWindow = (win: BrowserWindow): void => {
win.webContents.on('did-finish-load', emitMaximizeState)
}
const getWindowCloseBehavior = (): WindowCloseBehavior => {
const behavior = configService?.get('windowCloseBehavior')
return behavior === 'tray' || behavior === 'quit' ? behavior : 'ask'
}
const requestMainWindowCloseConfirmation = (win: BrowserWindow): void => {
if (isClosePromptVisible) return
isClosePromptVisible = true
win.webContents.send('window:confirmCloseRequested', {
canMinimizeToTray: Boolean(tray)
})
}
function createWindow(options: { autoShow?: boolean } = {}) {
// 获取图标路径 - 打包后在 resources 目录
const { autoShow = true } = options
@@ -357,12 +372,20 @@ function createWindow(options: { autoShow?: boolean } = {}) {
win.on('close', (e) => {
if (isAppQuitting || win !== mainWindow) return
e.preventDefault()
if (isClosePromptVisible) return
const closeBehavior = getWindowCloseBehavior()
isClosePromptVisible = true
win.webContents.send('window:confirmCloseRequested', {
canMinimizeToTray: Boolean(tray)
})
if (closeBehavior === 'quit') {
isAppQuitting = true
app.quit()
return
}
if (closeBehavior === 'tray' && tray) {
win.hide()
return
}
requestMainWindowCloseConfirmation(win)
})
win.on('closed', () => {