LCOV - code coverage report
Current view: top level - src/composables/queue - useResultGallery.ts Coverage Total Hit
Test: ComfyUI E2E Coverage Lines: 94.4 % 18 17
Test Date: 2026-11-17 04:17:53

            Line data    Source code
       1              : import { ref, shallowRef } from 'vue'
       2              : 
       3              : import type { JobListItem } from '@/composables/queue/useJobList'
       4              : import { openHdrViewer } from '@/services/hdrViewerService'
       5              : import { findActiveIndex, getOutputsForTask } from '@/services/jobOutputCache'
       6              : import type { TaskItemImpl } from '@/stores/queueStore'
       7              : import { isHdrImageFilename } from '@/utils/hdrFormatUtil'
       8              : import type { AugmentedResultItem } from '@/utils/resultItem'
       9              : import { resultItemUrl } from '@/utils/resultItemUrl'
      10              : 
      11              : /**
      12              :  * Manages result gallery state and activation for queue items.
      13              :  */
      14         2008 : export function useResultGallery(getFilteredTasks: () => TaskItemImpl[]) {
      15         2008 :   const galleryActiveIndex = ref(-1)
      16         2008 :   const galleryItems = shallowRef<AugmentedResultItem[]>([])
      17              : 
      18            1 :   async function onViewItem(item: JobListItem) {
      19            1 :     const tasks = getFilteredTasks()
      20            1 :     if (!tasks.length) return
      21              : 
      22            1 :     const targetTask = item.taskRef
      23            1 :     const targetOutputs = targetTask
      24              :       ? await getOutputsForTask(targetTask)
      25              :       : null
      26              : 
      27              :     // Request was superseded by a newer one
      28            1 :     if (targetOutputs === null && targetTask) return
      29              : 
      30            1 :     const previewOutput = targetTask?.previewOutput
      31            1 :     if (previewOutput && isHdrImageFilename(previewOutput.filename)) {
      32            1 :       openHdrViewer(resultItemUrl(previewOutput))
      33            1 :       return
      34              :     }
      35              : 
      36            1 :     const items = (
      37              :       targetOutputs?.length
      38              :         ? targetOutputs
      39              :         : tasks.map((t) => t.previewOutput).filter((o) => !!o)
      40              :     ).filter((o) => !isHdrImageFilename(o.filename))
      41            1 :     if (!items.length) return
      42              : 
      43            0 :     galleryItems.value = items
      44            1 :     galleryActiveIndex.value = findActiveIndex(
      45              :       items,
      46              :       previewOutput ? resultItemUrl(previewOutput) : undefined
      47              :     )
      48              :   }
      49              : 
      50         2008 :   return {
      51              :     galleryActiveIndex,
      52              :     galleryItems,
      53              :     onViewItem
      54              :   }
      55              : }
        

Generated by: LCOV version 2.0-1