Line data Source code
1 : <template>
2 : <div v-show="isVisible" class="pointer-events-none flex w-full justify-end">
3 : <div
4 : data-testid="queue-progress-overlay"
5 : class="pointer-events-auto flex max-h-[60vh] w-[350px] min-w-[310px] flex-col overflow-hidden rounded-lg border transition-colors duration-200 ease-in-out"
6 : :class="containerClass"
7 : @mouseenter="isHovered = true"
8 : @mouseleave="isHovered = false"
9 : >
10 : <!-- Expanded state -->
11 : <QueueOverlayExpanded
12 : v-if="isExpanded"
13 : v-model:selected-job-tab="selectedJobTab"
14 : v-model:selected-workflow-filter="selectedWorkflowFilter"
15 : v-model:selected-sort-mode="selectedSortMode"
16 : class="min-h-0 flex-1"
17 : :header-title="headerTitle"
18 : :queued-count="queuedCount"
19 : :displayed-job-groups="displayedJobGroups"
20 : :has-failed-jobs="hasFailedJobs"
21 : @show-assets="toggleAssetsSidebar"
22 : @clear-history="onClearHistoryFromMenu"
23 : @clear-queued="cancelQueuedWorkflows"
24 : @cancel-item="onCancelItem"
25 : @delete-item="onDeleteItem"
26 : @view-item="inspectJobAsset"
27 : />
28 :
29 : <QueueOverlayActive
30 : v-else-if="hasActiveJob"
31 : :total-progress-style="totalProgressStyle"
32 : :current-node-progress-style="currentNodeProgressStyle"
33 : :total-percent-formatted="totalPercentFormatted"
34 : :current-node-percent-formatted="currentNodePercentFormatted"
35 : :current-node-name="currentNodeName"
36 : :running-count="runningCount"
37 : :queued-count="queuedCount"
38 : :bottom-row-class="bottomRowClass"
39 : @interrupt-all="interruptAll"
40 : @clear-queued="cancelQueuedWorkflows"
41 : @view-all-jobs="viewAllJobs"
42 : />
43 : </div>
44 : </div>
45 :
46 : <MediaLightbox
47 : v-model:active-index="galleryActiveIndex"
48 : :all-gallery-items="galleryItems"
49 : />
50 : </template>
51 :
52 : <script setup lang="ts">
53 : import { computed, nextTick, ref } from 'vue'
54 : import { useI18n } from 'vue-i18n'
55 :
56 : import QueueOverlayActive from '@/components/queue/QueueOverlayActive.vue'
57 : import QueueOverlayExpanded from '@/components/queue/QueueOverlayExpanded.vue'
58 : import MediaLightbox from '@/components/sidebar/tabs/queue/MediaLightbox.vue'
59 : import { useJobList } from '@/composables/queue/useJobList'
60 : import type { JobListItem } from '@/composables/queue/useJobList'
61 : import { useQueueClearHistoryDialog } from '@/composables/queue/useQueueClearHistoryDialog'
62 : import { useQueueProgress } from '@/composables/queue/useQueueProgress'
63 : import { useResultGallery } from '@/composables/queue/useResultGallery'
64 : import { useErrorHandling } from '@/composables/useErrorHandling'
65 : import { useAssetSelectionStore } from '@/platform/assets/composables/useAssetSelectionStore'
66 : import { useSurveyFeatureTracking } from '@/platform/surveys/useSurveyFeatureTracking'
67 : import { api } from '@/scripts/api'
68 : import { useCommandStore } from '@/platform/keybindings/commandStore'
69 : import { useExecutionStore } from '@/stores/executionStore'
70 : import { useQueueStore } from '@/stores/queueStore'
71 : import { useAssetsStore } from '@/stores/assetsStore'
72 : import { useSidebarTabStore } from '@/stores/workspace/sidebarTabStore'
73 :
74 : type OverlayState = 'hidden' | 'active' | 'expanded'
75 :
76 : const { expanded, menuHovered } = defineProps<{
77 : expanded?: boolean
78 : menuHovered?: boolean
79 : }>()
80 :
81 1999 : const emit = defineEmits<{
82 : (e: 'update:expanded', value: boolean): void
83 : }>()
84 :
85 1999 : const { t, n } = useI18n()
86 1999 : const queueStore = useQueueStore()
87 1999 : const commandStore = useCommandStore()
88 1999 : const executionStore = useExecutionStore()
89 1999 : const assetsStore = useAssetsStore()
90 1999 : const sidebarTabStore = useSidebarTabStore()
91 1999 : const assetSelectionStore = useAssetSelectionStore()
92 1999 : const { showQueueClearHistoryDialog } = useQueueClearHistoryDialog()
93 1999 : const { wrapWithErrorHandlingAsync } = useErrorHandling()
94 1999 : const { trackFeatureUsed } = useSurveyFeatureTracking('queue-progress-overlay')
95 :
96 1999 : const {
97 : totalPercentFormatted,
98 : currentNodePercentFormatted,
99 : totalProgressStyle,
100 : currentNodeProgressStyle
101 : } = useQueueProgress()
102 1999 : const isHovered = ref(false)
103 1999 : const isOverlayHovered = computed(() => isHovered.value || menuHovered)
104 1999 : const internalExpanded = ref(false)
105 1999 : const isExpanded = computed({
106 : get: () => (expanded === undefined ? internalExpanded.value : expanded),
107 : set: (value) => {
108 0 : if (expanded === undefined) {
109 0 : internalExpanded.value = value
110 : }
111 0 : emit('update:expanded', value)
112 : }
113 : })
114 :
115 1999 : const runningCount = computed(() => queueStore.runningTasks.length)
116 1999 : const queuedCount = computed(() => queueStore.pendingTasks.length)
117 1999 : const isExecuting = computed(() => !executionStore.isIdle)
118 1999 : const hasActiveJob = computed(() => runningCount.value > 0 || isExecuting.value)
119 :
120 1999 : const overlayState = computed<OverlayState>(() => {
121 2229 : if (isExpanded.value) return 'expanded'
122 2226 : if (hasActiveJob.value) return 'active'
123 2085 : return 'hidden'
124 : })
125 :
126 1999 : const showBackground = computed(
127 : () =>
128 : overlayState.value === 'expanded' ||
129 : (overlayState.value === 'active' && isOverlayHovered.value)
130 : )
131 :
132 1999 : const isVisible = computed(() => overlayState.value !== 'hidden')
133 :
134 1999 : const containerClass = computed(() =>
135 : showBackground.value
136 : ? 'border-border bg-background shadow-md'
137 : : 'border-transparent bg-transparent shadow-none'
138 : )
139 :
140 1999 : const bottomRowClass = computed(
141 : () =>
142 : `flex items-center justify-end gap-4 transition-opacity duration-200 ease-in-out ${
143 : overlayState.value === 'active' && isOverlayHovered.value
144 : ? 'opacity-100 pointer-events-auto'
145 : : 'opacity-0 pointer-events-none'
146 : }`
147 : )
148 1999 : const runningJobsLabel = computed(() =>
149 : t('sideToolbar.queueProgressOverlay.runningJobsLabel', {
150 : count: n(runningCount.value)
151 : })
152 : )
153 1999 : const queuedJobsLabel = computed(() =>
154 : t('sideToolbar.queueProgressOverlay.queuedJobsLabel', {
155 : count: n(queuedCount.value)
156 : })
157 : )
158 1999 : const headerTitle = computed(() => {
159 21 : if (!hasActiveJob.value) {
160 20 : return t('sideToolbar.queueProgressOverlay.jobQueue')
161 : }
162 :
163 1 : if (queuedCount.value === 0) {
164 0 : return runningJobsLabel.value
165 : }
166 :
167 1 : if (runningCount.value === 0) {
168 0 : return queuedJobsLabel.value
169 : }
170 :
171 1 : return t('sideToolbar.queueProgressOverlay.runningQueuedSummary', {
172 : running: runningJobsLabel.value,
173 : queued: queuedJobsLabel.value
174 : })
175 : })
176 :
177 1999 : const {
178 : selectedJobTab,
179 : selectedWorkflowFilter,
180 : selectedSortMode,
181 : hasFailedJobs,
182 : filteredTasks,
183 : groupedJobItems,
184 : currentNodeName
185 : } = useJobList()
186 :
187 1999 : const displayedJobGroups = computed(() => groupedJobItems.value)
188 :
189 1999 : const onCancelItem = wrapWithErrorHandlingAsync(async (item: JobListItem) => {
190 0 : trackFeatureUsed()
191 0 : const jobId = item.taskRef?.jobId
192 0 : if (!jobId) return
193 :
194 0 : if (
195 : item.state === 'running' ||
196 : item.state === 'initialization' ||
197 : item.state === 'pending'
198 : ) {
199 : // State-agnostic cancel (see api.ts cancelJob for the runtime-parity caveat).
200 0 : await api.cancelJob(jobId)
201 0 : executionStore.clearInitializationByJobId(jobId)
202 0 : await queueStore.update()
203 : }
204 : })
205 :
206 1999 : const onDeleteItem = wrapWithErrorHandlingAsync(async (item: JobListItem) => {
207 0 : trackFeatureUsed()
208 0 : if (!item.taskRef) return
209 0 : await queueStore.delete(item.taskRef)
210 : })
211 :
212 1999 : const {
213 : galleryActiveIndex,
214 : galleryItems,
215 : onViewItem: openResultGallery
216 : } = useResultGallery(() => filteredTasks.value)
217 :
218 1999 : const setExpanded = (expanded: boolean) => {
219 0 : isExpanded.value = expanded
220 : }
221 :
222 1999 : const viewAllJobs = () => {
223 0 : trackFeatureUsed()
224 0 : setExpanded(true)
225 : }
226 :
227 1999 : const toggleAssetsSidebar = () => {
228 0 : trackFeatureUsed()
229 0 : sidebarTabStore.toggleSidebarTab('assets')
230 : }
231 :
232 1999 : const openAssetsSidebar = () => {
233 0 : sidebarTabStore.activeSidebarTabId = 'assets'
234 : }
235 :
236 1999 : let assetFocusRequest = 0
237 :
238 1999 : const focusAssetInSidebar = async (item: JobListItem, request: number) => {
239 0 : const task = item.taskRef
240 0 : const jobId = task?.jobId
241 0 : const preview = task?.previewOutput
242 0 : if (!jobId || !preview || request !== assetFocusRequest) return
243 :
244 0 : const assetId = String(jobId)
245 0 : openAssetsSidebar()
246 0 : await nextTick()
247 : const found = await assetsStore.loadOutputAsset(assetId)
248 0 : if (!found || request !== assetFocusRequest) return
249 :
250 0 : assetSelectionStore.setSelection([assetId])
251 0 : assetSelectionStore.setLastSelectedAssetId(assetId)
252 : }
253 :
254 1999 : const inspectJobAsset = wrapWithErrorHandlingAsync(
255 : async (item: JobListItem) => {
256 0 : const request = ++assetFocusRequest
257 0 : trackFeatureUsed()
258 0 : await openResultGallery(item)
259 0 : await focusAssetInSidebar(item, request)
260 : }
261 : )
262 :
263 1999 : const cancelQueuedWorkflows = wrapWithErrorHandlingAsync(async () => {
264 0 : trackFeatureUsed()
265 : // Capture pending jobIds before clearing
266 0 : const pendingJobIds = queueStore.pendingTasks
267 : .map((task) => task.jobId)
268 : .filter((id): id is string => typeof id === 'string' && id.length > 0)
269 :
270 0 : await commandStore.execute('Comfy.ClearPendingTasks')
271 :
272 : // Clear initialization state for removed jobs
273 0 : executionStore.clearInitializationByJobIds(pendingJobIds)
274 : })
275 :
276 1999 : const interruptAll = wrapWithErrorHandlingAsync(async () => {
277 0 : trackFeatureUsed()
278 : const tasks = queueStore.runningTasks
279 0 : const jobIds = tasks
280 : .map((task) => task.jobId)
281 : .filter((id): id is string => typeof id === 'string' && id.length > 0)
282 :
283 0 : if (!jobIds.length) return
284 :
285 : // State-agnostic batch cancel (see api.ts cancelJobs for the runtime-parity caveat).
286 0 : await api.cancelJobs(jobIds)
287 0 : executionStore.clearInitializationByJobIds(jobIds)
288 0 : await queueStore.update()
289 : })
290 :
291 1999 : const onClearHistoryFromMenu = () => {
292 8 : trackFeatureUsed()
293 8 : showQueueClearHistoryDialog()
294 : }
295 : </script>
|