feat(menu): 队列处理完不再自动关窗,按任意键(Esc/Enter)关闭

- 队列清空后显示汇总并驻留窗口:按任意键关闭,2 分钟无操作才自动关闭
- 驻留期间若有新任务入队,同一个窗口会继续处理,不必重新点菜单
- 汇总把成功/取消/失败分三档计数
This commit is contained in:
ali
2026-11-19 18:43:01 +08:00
parent 0819f784eb
commit cc49b00e1f
+31 -7
View File
@@ -179,17 +179,21 @@ function Invoke-Worker {
try { $Host.UI.RawUI.WindowTitle = 'SceneMarshal 队列' } catch { }
Write-WorkerLog ("worker 启动(stdin重定向={0} stdout重定向={1})" -f `
[Console]::IsInputRedirected, [Console]::IsOutputRedirected)
Write-Host '📋 SceneMarshal 队列已启动(处理完即退出)' -ForegroundColor Cyan
Write-Host '📋 SceneMarshal 队列已启动' -ForegroundColor Cyan
Write-Host ''
$done = 0
$failed = 0
$cancelled = 0
$summaryShown = $false
$closeDeadline = $null
while ($true) {
$item = Take-QueueItem
if ($null -eq $item) { break } # 队列空就退出,不再等待新任务
if ($null -ne $item) {
$summaryShown = $false
$closeDeadline = $null
$name = Split-Path -Leaf $item.path
Write-Host ('─── [{0}] {1}' -f $item.action, $name) -ForegroundColor Yellow
Write-WorkerLog ("开始处理 {0} :: {1}" -f $item.action, $item.path)
@@ -219,14 +223,34 @@ function Invoke-Worker {
Write-WorkerLog ("失败 {0}(code={1}, {2}s)" -f $item.path, $code, $cost)
}
Write-Host ''
continue
}
$total = $done + $cancelled + $failed
Write-Host ('📊 本次共处理 {0} 项:成功 {1},取消 {2},失败 {3}' -f $total, $done, $cancelled, $failed) -ForegroundColor Cyan
Write-Host ' 队列已空,窗口即将关闭(详细记录见 worker.log)' -ForegroundColor DarkGray
Write-WorkerLog ("worker 退出:成功 {0},取消 {1},失败 {2}" -f $done, $cancelled, $failed)
# 队列已空:只显示一次汇总,然后等按键关闭窗口
if (-not $summaryShown) {
Write-Host ('📊 本次共处理 {0} 项:成功 {1},取消 {2},失败 {3}' -f `
($done + $cancelled + $failed), $done, $cancelled, $failed) -ForegroundColor Cyan
Write-Host ' 按任意键(Esc / Enter)关闭窗口;期间有新任务会接着处理(2 分钟无操作自动关闭)' -ForegroundColor DarkGray
Write-WorkerLog ("队列处理完毕:成功 {0},取消 {1},失败 {2}" -f $done, $cancelled, $failed)
$summaryShown = $true
$closeDeadline = (Get-Date).AddSeconds(120)
}
$pressed = $false
try {
if ($Host.UI.RawUI.KeyAvailable) {
$null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown')
$pressed = $true
}
}
catch { }
if ($pressed) { break }
if ($null -ne $closeDeadline -and (Get-Date) -ge $closeDeadline) { break }
Start-Sleep -Milliseconds 150
}
Write-WorkerLog 'worker 退出'
$workerLock.Close()
if ($total -gt 0) { Start-Sleep -Seconds 2 } # 留两秒给汇总留在屏幕上
return 0
}