Files
ComfyUI_frontend/src/composables/queue/useCompletionSummary.ts
Benjamin Lu e42715086e Implement workflow progress panel (#6092)
Adds a workflow progress panel component underneath the
`actionbar-container`.

I suggest starting a review at the extraneous changes that were needed.
Including but not limited to:

- `get createTime()` in queueStore
- `promptIdToWorkflowId`, `initializingPromptIds`, and
`nodeProgressStatesByPrompt` in executionStore
- `create_time` handling in v2ToV1Adapter
- `pointer-events-auto` on ComfyActionbar.vue

The rest of the changes should be contained under
`QueueProgressOverlay.vue`, and has less of a blast radius in case
something goes wrong.

---------

Co-authored-by: pythongosssss <125205205+pythongosssss@users.noreply.github.com>
Co-authored-by: GitHub Action <action@github.com>
Co-authored-by: github-actions <github-actions@github.com>
Co-authored-by: Jin Yi <jin12cc@gmail.com>
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Alexander Brown <drjkl@comfy.org>
Co-authored-by: Johnpaul Chiwetelu <49923152+Myestery@users.noreply.github.com>
Co-authored-by: Christian Byrne <cbyrne@comfy.org>
Co-authored-by: Comfy Org PR Bot <snomiao+comfy-pr@gmail.com>
Co-authored-by: christian-byrne <72887196+christian-byrne@users.noreply.github.com>
2025-11-18 22:43:49 -08:00

117 lines
3.0 KiB
TypeScript

import { computed, ref, watch } from 'vue'
import { useExecutionStore } from '@/stores/executionStore'
import { useQueueStore } from '@/stores/queueStore'
import { jobStateFromTask } from '@/utils/queueUtil'
export type CompletionSummaryMode = 'allSuccess' | 'mixed' | 'allFailed'
export type CompletionSummary = {
mode: CompletionSummaryMode
completedCount: number
failedCount: number
thumbnailUrls: string[]
}
/**
* Tracks queue activity transitions and exposes a short-lived summary of the
* most recent generation batch.
*/
export const useCompletionSummary = () => {
const queueStore = useQueueStore()
const executionStore = useExecutionStore()
const isActive = computed(
() => queueStore.runningTasks.length > 0 || !executionStore.isIdle
)
const lastActiveStartTs = ref<number | null>(null)
const _summary = ref<CompletionSummary | null>(null)
const dismissTimer = ref<number | null>(null)
const clearDismissTimer = () => {
if (dismissTimer.value !== null) {
clearTimeout(dismissTimer.value)
dismissTimer.value = null
}
}
const startDismissTimer = () => {
clearDismissTimer()
dismissTimer.value = window.setTimeout(() => {
_summary.value = null
dismissTimer.value = null
}, 6000)
}
const clearSummary = () => {
_summary.value = null
clearDismissTimer()
}
watch(
isActive,
(active, prev) => {
if (!prev && active) {
lastActiveStartTs.value = Date.now()
}
if (prev && !active) {
const start = lastActiveStartTs.value ?? 0
const finished = queueStore.historyTasks.filter((t: any) => {
const ts: number | undefined = t.executionEndTimestamp
return typeof ts === 'number' && ts >= start
})
if (!finished.length) {
_summary.value = null
clearDismissTimer()
return
}
let completedCount = 0
let failedCount = 0
const imagePreviews: string[] = []
for (const task of finished) {
const state = jobStateFromTask(task, false)
if (state === 'completed') {
completedCount++
const preview = task.previewOutput
if (preview?.isImage) {
imagePreviews.push(preview.urlWithTimestamp)
}
} else if (state === 'failed') {
failedCount++
}
}
if (completedCount === 0 && failedCount === 0) {
_summary.value = null
clearDismissTimer()
return
}
let mode: CompletionSummaryMode = 'mixed'
if (failedCount === 0) mode = 'allSuccess'
else if (completedCount === 0) mode = 'allFailed'
_summary.value = {
mode,
completedCount,
failedCount,
thumbnailUrls: imagePreviews.slice(0, 3)
}
startDismissTimer()
}
},
{ immediate: true }
)
const summary = computed(() => _summary.value)
return {
summary,
clearSummary
}
}