LCOV - code coverage report
Current view: top level - src/components/actionbar - ComfyActionbar.vue Coverage Total Hit
Test: ComfyUI E2E Coverage Lines: 86.7 % 128 111
Test Date: 2026-11-17 04:17:53

            Line data    Source code
       1              : <template>
       2         8503 :   <div :class="cn('flex h-full items-center', !isDocked && '-ml-2')">
       3              :     <div
       4              :       v-if="isDragging && !isDocked"
       5              :       :class="
       6              :         cn(
       7              :           'pointer-events-auto m-1.5 flex w-50 items-center justify-center self-stretch rounded-md border-dashed border-blue-500 opacity-80 before:-ml-50 before:h-full before:w-50',
       8              :           isMouseOverDropZone &&
       9              :             'scale-105 border-[3px] opacity-100 shadow-[0_0_20px] shadow-blue-500'
      10              :         )
      11              :       "
      12              :       @mouseenter="onMouseEnterDropZone"
      13              :       @mouseleave="onMouseLeaveDropZone"
      14              :     >
      15              :       {{ t('actionbar.dockToTop') }}
      16              :     </div>
      17              : 
      18              :     <div
      19              :       ref="panelRef"
      20              :       :style
      21              :       :class="
      22              :         cn(
      23              :           'actionbar pointer-events-auto',
      24              :           isDragging && 'pointer-events-none select-none',
      25              :           !isDocked && 'fixed z-1 floating-panel'
      26              :         )
      27              :       "
      28              :       data-testid="actionbar-panel"
      29              :     >
      30              :       <div class="relative flex items-center gap-2 select-none">
      31              :         <span
      32              :           ref="dragHandleRef"
      33              :           :class="
      34              :             cn(
      35              :               'drag-handle h-max w-3 cursor-grab',
      36              :               isDragging && 'cursor-grabbing'
      37              :             )
      38              :           "
      39              :         />
      40              :         <DeploymentSwitcher />
      41              :         <div v-coachmark="FIRST_RUN_COACH_IDS.runButton" class="inline-flex">
      42              :           <Suspense @resolve="comfyRunButtonResolved">
      43              :             <ComfyRunButton />
      44              :           </Suspense>
      45              :         </div>
      46              :         <Button
      47              :           :tooltip="t('menu.interrupt')"
      48              :           tooltip-side="bottom"
      49              :           :variant="canInterrupt ? 'destructive' : 'secondary'"
      50              :           size="icon"
      51              :           :disabled="!canInterrupt"
      52              :           :aria-label="t('menu.interrupt')"
      53              :           @click="cancelCurrentJob"
      54              :         >
      55              :           <i class="icon-[lucide--x]" />
      56              :         </Button>
      57              :         <ContextMenu :model="queueContextMenuItems">
      58              :           <Button
      59              :             :tooltip="queueToggleLabel"
      60              :             tooltip-side="bottom"
      61              :             variant="secondary"
      62              :             size="md"
      63              :             :aria-pressed="
      64              :               isQueuePanelV2Enabled
      65              :                 ? activeSidebarTabId === 'job-history'
      66              :                 : queueOverlayExpanded
      67              :             "
      68              :             class="px-3"
      69              :             data-testid="queue-overlay-toggle"
      70              :             @click="toggleQueueOverlay"
      71              :             @contextmenu.stop
      72              :           >
      73              :             <span class="text-sm font-normal tabular-nums">
      74              :               {{ activeJobsLabel }}
      75              :             </span>
      76              :             <Badge
      77              :               v-if="activeJobsCount > 0"
      78              :               data-testid="active-jobs-indicator"
      79              :               variant="dot"
      80              :               severity="default"
      81              :               class="pointer-events-none absolute -top-0.5 -right-0.5 animate-pulse"
      82              :             />
      83              :             <span class="sr-only">{{ queueToggleLabel }}</span>
      84              :           </Button>
      85              :         </ContextMenu>
      86              :       </div>
      87              :       <FreeTierQuota v-if="!isDocked" />
      88              :       <PartnerNodesRunCaption v-if="!isDocked" />
      89              :     </div>
      90              : 
      91              :     <Teleport
      92              :       v-if="inlineProgressTarget"
      93              :       :key="isDocked ? 'docked' : 'floating'"
      94              :       :to="inlineProgressTarget"
      95              :     >
      96              :       <QueueInlineProgress
      97              :         :hidden="shouldHideInlineProgress"
      98              :         radius-class="rounded-xl"
      99              :         data-testid="queue-inline-progress"
     100              :       />
     101              :     </Teleport>
     102              :   </div>
     103              : </template>
     104              : 
     105              : <script lang="ts" setup>
     106              : import {
     107              :   useDraggable,
     108              :   useEventListener,
     109              :   useLocalStorage,
     110              :   useResizeObserver,
     111              :   watchDebounced
     112              : } from '@vueuse/core'
     113              : import { clamp } from 'es-toolkit/compat'
     114              : import { storeToRefs } from 'pinia'
     115              : import { computed, nextTick, ref, watch } from 'vue'
     116              : import { useI18n } from 'vue-i18n'
     117              : 
     118              : import PartnerNodesRunCaption from '@/components/actionbar/PartnerNodesRunCaption.vue'
     119              : import Badge from '@comfyorg/design-system/badge/Badge'
     120              : import QueueInlineProgress from '@/components/queue/QueueInlineProgress.vue'
     121              : import Button from '@comfyorg/design-system/button/Button'
     122              : import ContextMenu from '@comfyorg/design-system/menu/ContextMenu'
     123              : import type { MenuItem } from '@comfyorg/design-system/lib/menu/types'
     124              : import { useInterruptibleJob } from '@/components/queue/useInterruptibleJob'
     125              : import { useQueueFeatureFlags } from '@/composables/queue/useQueueFeatureFlags'
     126              : import FreeTierQuota from '@/platform/billing/subscription/components/FreeTierQuota.vue'
     127              : import { useSettingStore } from '@/platform/settings/settingStore'
     128              : import DeploymentSwitcher from '@/platform/workspace/components/DeploymentSwitcher.vue'
     129              : import { useTelemetry } from '@comfyorg/telemetry'
     130              : import { useCommandStore } from '@/platform/keybindings/commandStore'
     131              : import { useExecutionStore } from '@/stores/executionStore'
     132              : import { FIRST_RUN_COACH_IDS } from '@/platform/onboarding/onboardingTours'
     133              : import { vCoachmark } from '@/platform/onboarding/vCoachmark'
     134              : import { useQueueStore } from '@/stores/queueStore'
     135              : import { useSidebarTabStore } from '@/stores/workspace/sidebarTabStore'
     136              : import { cn } from '@comfyorg/tailwind-utils'
     137              : 
     138              : import ComfyRunButton from './ComfyRunButton/ComfyRunButton.vue'
     139              : 
     140              : const { dockedProgressContainer, queueOverlayExpanded = false } = defineProps<{
     141              :   /**
     142              :    * Element the inline run-progress bar is teleported into while the actionbar
     143              :    * is docked. Must be the bordered actionbar card, not the inner button row —
     144              :    * the bar is `absolute inset-0` and sits flush with its container's bottom.
     145              :    */
     146              :   dockedProgressContainer?: HTMLElement | null
     147              :   queueOverlayExpanded?: boolean
     148              : }>()
     149              : 
     150         2009 : const emit = defineEmits<{
     151              :   (event: 'update:progressTarget', target: HTMLElement | null): void
     152              : }>()
     153              : 
     154         2009 : const settingStore = useSettingStore()
     155         2009 : const commandStore = useCommandStore()
     156         2009 : const executionStore = useExecutionStore()
     157         2009 : const queueStore = useQueueStore()
     158         2009 : const sidebarTabStore = useSidebarTabStore()
     159         2009 : const { t, n } = useI18n()
     160         2009 : const { interruptibleJobId, canInterrupt } = useInterruptibleJob()
     161         2009 : const { activeJobsCount } = storeToRefs(queueStore)
     162         2009 : const { activeSidebarTabId } = storeToRefs(sidebarTabStore)
     163              : 
     164         2009 : const position = computed(() => settingStore.get('Comfy.UseNewMenu'))
     165         2009 : const visible = computed(() => position.value !== 'Disabled')
     166         2009 : const { isQueuePanelV2Enabled, isRunProgressBarEnabled } =
     167              :   useQueueFeatureFlags()
     168              : 
     169         2009 : const panelRef = ref<HTMLElement | null>(null)
     170         2009 : const dragHandleRef = ref<HTMLElement | null>(null)
     171         2009 : const isDocked = useLocalStorage('Comfy.MenuPosition.Docked', true)
     172         2009 : const storedPosition = useLocalStorage('Comfy.MenuPosition.Floating', {
     173              :   x: 0,
     174              :   y: 0
     175              : })
     176         2009 : const { x, y, style, isDragging } = useDraggable(panelRef, {
     177              :   initialValue: { x: 0, y: 0 },
     178              :   handle: dragHandleRef,
     179              :   containerElement: document.body
     180              : })
     181              : 
     182              : // Update storedPosition when x or y changes
     183         2009 : watchDebounced(
     184              :   [x, y],
     185              :   ([newX, newY]) => {
     186         1973 :     storedPosition.value = { x: newX, y: newY }
     187              :   },
     188              :   { debounce: 300 }
     189              : )
     190              : 
     191              : // Set initial position to bottom center
     192         2009 : const setInitialPosition = () => {
     193         1999 :   const panel = panelRef.value
     194         1999 :   if (panel) {
     195         1999 :     const screenWidth = window.innerWidth
     196         1999 :     const screenHeight = window.innerHeight
     197         1999 :     const menuWidth = panel.offsetWidth
     198         1999 :     const menuHeight = panel.offsetHeight
     199              : 
     200         1999 :     if (menuWidth === 0 || menuHeight === 0) {
     201            7 :       return
     202              :     }
     203              : 
     204              :     // Check if stored position exists and is within bounds
     205         1999 :     if (storedPosition.value.x !== 0 || storedPosition.value.y !== 0) {
     206              :       // Ensure stored position is within screen bounds
     207          110 :       x.value = clamp(storedPosition.value.x, 0, screenWidth - menuWidth)
     208          110 :       y.value = clamp(storedPosition.value.y, 0, screenHeight - menuHeight)
     209          110 :       captureLastDragState()
     210          110 :       return
     211              :     }
     212              : 
     213              :     // If no stored position or current position, set to bottom center
     214         1999 :     if (x.value === 0 && y.value === 0) {
     215         1882 :       x.value = clamp((screenWidth - menuWidth) / 2, 0, screenWidth - menuWidth)
     216         1882 :       y.value = clamp(
     217              :         screenHeight - menuHeight - 10,
     218              :         0,
     219              :         screenHeight - menuHeight
     220              :       )
     221         1882 :       captureLastDragState()
     222              :     }
     223              :   }
     224              : }
     225              : 
     226              : //The ComfyRunButton is a dynamic import. Which means it will not be loaded onMount in this component.
     227              : //So we must use suspense resolve to ensure that is has loaded and updated the DOM before calling setInitialPosition()
     228         1999 : async function comfyRunButtonResolved() {
     229         1999 :   await nextTick()
     230         1999 :   setInitialPosition()
     231              : }
     232              : 
     233         2009 : watch(visible, async (newVisible) => {
     234            0 :   if (newVisible) {
     235            0 :     await nextTick(setInitialPosition)
     236              :   }
     237              : })
     238              : 
     239              : /**
     240              :  * Track run button handle drag start using mousedown on the drag handle.
     241              :  */
     242         2009 : useEventListener(dragHandleRef, 'mousedown', () => {
     243            2 :   useTelemetry()?.trackUiButtonClicked({
     244              :     button_id: 'actionbar_run_handle_drag_start',
     245              :     element_group: 'actionbar'
     246              :   })
     247              : })
     248              : 
     249         2009 : const lastDragState = ref({
     250              :   x: x.value,
     251              :   y: y.value,
     252              :   windowWidth: window.innerWidth,
     253              :   windowHeight: window.innerHeight
     254              : })
     255         2009 : const captureLastDragState = () => {
     256         4003 :   lastDragState.value = {
     257              :     x: x.value,
     258              :     y: y.value,
     259              :     windowWidth: window.innerWidth,
     260              :     windowHeight: window.innerHeight
     261              :   }
     262              : }
     263         2009 : watch(
     264              :   isDragging,
     265              :   (newIsDragging) => {
     266         2013 :     if (!newIsDragging) {
     267              :       // Stop dragging
     268         2011 :       captureLastDragState()
     269              :     }
     270              :   },
     271              :   { immediate: true }
     272              : )
     273              : 
     274         2009 : const adjustMenuPosition = () => {
     275           68 :   const panel = panelRef.value
     276           68 :   if (panel) {
     277           68 :     const screenWidth = window.innerWidth
     278           68 :     const screenHeight = window.innerHeight
     279           68 :     const menuWidth = panel.offsetWidth
     280           68 :     const menuHeight = panel.offsetHeight
     281              : 
     282              :     // Calculate distances to all edges
     283           68 :     const distanceLeft = lastDragState.value.x
     284           68 :     const distanceRight =
     285              :       lastDragState.value.windowWidth - (lastDragState.value.x + menuWidth)
     286           68 :     const distanceTop = lastDragState.value.y
     287           68 :     const distanceBottom =
     288              :       lastDragState.value.windowHeight - (lastDragState.value.y + menuHeight)
     289              : 
     290              :     // Find the smallest distance to determine which edge to anchor to
     291              :     const distances = [
     292              :       { edge: 'left', distance: distanceLeft },
     293              :       { edge: 'right', distance: distanceRight },
     294              :       { edge: 'top', distance: distanceTop },
     295              :       { edge: 'bottom', distance: distanceBottom }
     296              :     ]
     297           68 :     const closestEdge = distances.reduce((min, curr) =>
     298              :       curr.distance < min.distance ? curr : min
     299              :     )
     300              : 
     301              :     // Calculate vertical position as a percentage of screen height
     302           68 :     const verticalRatio =
     303              :       lastDragState.value.y / lastDragState.value.windowHeight
     304           68 :     const horizontalRatio =
     305              :       lastDragState.value.x / lastDragState.value.windowWidth
     306              : 
     307              :     // Apply positioning based on closest edge
     308           68 :     if (closestEdge.edge === 'left') {
     309            0 :       x.value = closestEdge.distance // Maintain exact distance from left
     310            0 :       y.value = verticalRatio * screenHeight
     311           68 :     } else if (closestEdge.edge === 'right') {
     312            0 :       x.value = screenWidth - menuWidth - closestEdge.distance // Maintain exact distance from right
     313            0 :       y.value = verticalRatio * screenHeight
     314           68 :     } else if (closestEdge.edge === 'top') {
     315            0 :       x.value = horizontalRatio * screenWidth
     316            0 :       y.value = closestEdge.distance // Maintain exact distance from top
     317              :     } else {
     318              :       // bottom
     319           68 :       x.value = horizontalRatio * screenWidth
     320           68 :       y.value = screenHeight - menuHeight - closestEdge.distance // Maintain exact distance from bottom
     321              :     }
     322              : 
     323              :     // Ensure the menu stays within the screen bounds
     324           68 :     x.value = clamp(x.value, 0, screenWidth - menuWidth)
     325           68 :     y.value = clamp(y.value, 0, screenHeight - menuHeight)
     326              :   }
     327              : }
     328              : 
     329         2009 : useEventListener(window, 'resize', adjustMenuPosition)
     330              : 
     331         4122 : function keepFloatingPanelOnScreen() {
     332         4122 :   const panel = panelRef.value
     333         4122 :   if (!panel || isDocked.value) return
     334            0 :   x.value = clamp(x.value, 0, window.innerWidth - panel.offsetWidth)
     335            0 :   y.value = clamp(y.value, 0, window.innerHeight - panel.offsetHeight)
     336              : }
     337              : 
     338         2009 : useResizeObserver(panelRef, keepFloatingPanelOnScreen)
     339              : 
     340              : // Drop zone state
     341         2009 : const isMouseOverDropZone = ref(false)
     342              : 
     343              : // Mouse event handlers for self-contained drop zone
     344         2009 : const onMouseEnterDropZone = () => {
     345            2 :   if (isDragging.value) {
     346            2 :     isMouseOverDropZone.value = true
     347              :   }
     348              : }
     349              : 
     350         2009 : const onMouseLeaveDropZone = () => {
     351            1 :   if (isDragging.value) {
     352            1 :     isMouseOverDropZone.value = false
     353              :   }
     354              : }
     355              : 
     356         2009 : const inlineProgressTarget = computed(() => {
     357         2021 :   if (
     358              :     !visible.value ||
     359              :     !isQueuePanelV2Enabled.value ||
     360              :     !isRunProgressBarEnabled.value
     361              :   ) {
     362         1999 :     return null
     363              :   }
     364           22 :   if (isDocked.value) return dockedProgressContainer ?? null
     365            0 :   return panelRef.value
     366              : })
     367         2009 : const shouldHideInlineProgress = computed(
     368              :   () => !isQueuePanelV2Enabled.value && queueOverlayExpanded
     369              : )
     370         2009 : watch(
     371              :   panelRef,
     372              :   (target) => {
     373         4018 :     emit('update:progressTarget', target)
     374              :   },
     375              :   { immediate: true }
     376              : )
     377              : 
     378              : // Handle drag state changes
     379         2009 : watch(isDragging, (dragging) => {
     380            4 :   if (dragging) {
     381              :     // Starting to drag - undock if docked
     382            2 :     if (isDocked.value) {
     383            2 :       isDocked.value = false
     384              :     }
     385              :   } else {
     386              :     // Stopped dragging - dock if mouse is over drop zone
     387            2 :     if (isMouseOverDropZone.value) {
     388            1 :       isDocked.value = true
     389              :     }
     390              :     // Reset drop zone state
     391            2 :     isMouseOverDropZone.value = false
     392              :   }
     393              : })
     394              : 
     395         2009 : const queueToggleLabel = computed(() =>
     396              :   t(
     397              :     isQueuePanelV2Enabled.value
     398              :       ? 'sideToolbar.queueProgressOverlay.viewJobHistory'
     399              :       : 'sideToolbar.queueProgressOverlay.expandCollapsedQueue'
     400              :   )
     401              : )
     402         2009 : const activeJobsLabel = computed(() => {
     403         2063 :   const count = activeJobsCount.value
     404         2063 :   return t(
     405              :     'sideToolbar.queueProgressOverlay.activeJobsShort',
     406              :     { count: n(count) },
     407              :     count
     408              :   )
     409              : })
     410         2009 : const queueContextMenuItems = computed<MenuItem[]>(() => [
     411              :   {
     412              :     label: t('sideToolbar.queueProgressOverlay.clearQueueTooltip'),
     413              :     icon: 'icon-[lucide--list-x] text-destructive',
     414              :     class: '*:text-destructive',
     415              :     disabled: queueStore.pendingTasks.length === 0,
     416              :     command: () => {
     417            0 :       void handleClearQueue()
     418              :     }
     419              :   }
     420              : ])
     421              : 
     422         2009 : const cancelCurrentJob = async () => {
     423            2 :   const jobId = interruptibleJobId.value
     424            2 :   if (!jobId) return
     425            2 :   await commandStore.execute('Comfy.Interrupt', { metadata: { jobId } })
     426              : }
     427         2009 : const toggleQueueOverlay = () => {
     428           22 :   if (isQueuePanelV2Enabled.value) {
     429            0 :     sidebarTabStore.toggleSidebarTab('job-history')
     430            0 :     return
     431              :   }
     432           22 :   commandStore.execute('Comfy.Queue.ToggleOverlay')
     433              : }
     434         2009 : const handleClearQueue = async () => {
     435            0 :   const pendingJobIds = queueStore.pendingTasks
     436              :     .map((task) => task.jobId)
     437              :     .filter((id): id is string => typeof id === 'string' && id.length > 0)
     438              : 
     439            0 :   await commandStore.execute('Comfy.ClearPendingTasks')
     440            0 :   executionStore.clearInitializationByJobIds(pendingJobIds)
     441              : }
     442              : </script>
        

Generated by: LCOV version 2.0-1