LCOV - code coverage report
Current view: top level - src/renderer/extensions/linearMode - LinearControls.vue Coverage Total Hit
Test: ComfyUI E2E Coverage Lines: 91.5 % 47 43
Test Date: 2026-11-17 04:17:53

            Line data    Source code
       1              : <script setup lang="ts">
       2              : import { useTimeout } from '@vueuse/core'
       3              : import { PopoverArrow, PopoverRoot, PopoverTrigger } from 'reka-ui'
       4              : import { cn } from '@comfyorg/tailwind-utils'
       5              : import { storeToRefs } from 'pinia'
       6              : import { computed, ref, toValue, useTemplateRef } from 'vue'
       7              : import { useI18n } from 'vue-i18n'
       8              : 
       9              : import AppModeWidgetList from '@/components/builder/AppModeWidgetList.vue'
      10              : import { useErrorOverlayState } from '@/platform/workflowErrors/overlay/useErrorOverlayState'
      11              : import Loader from '@/components/loader/Loader.vue'
      12              : import ScrubableNumberInput from '@/components/common/ScrubableNumberInput.vue'
      13              : import { COACH_IDS } from '@/platform/onboarding/onboardingTours'
      14              : import { useOnboardingTourStore } from '@/platform/onboarding/onboardingTourStore'
      15              : import { vCoachmark } from '@/platform/onboarding/vCoachmark'
      16              : import PopoverContent from '@comfyorg/design-system/popover/PopoverContent'
      17              : import Button from '@comfyorg/design-system/button/Button'
      18              : import { useBillingContext } from '@/platform/billing/composables/useBillingContext'
      19              : import { isCloud } from '@/platform/distribution/types'
      20              : import FreeTierQuota from '@/platform/billing/subscription/components/FreeTierQuota.vue'
      21              : import SubscribeToRunButton from '@/platform/billing/subscription/components/SubscribeToRun.vue'
      22              : import { useSettingStore } from '@/platform/settings/settingStore'
      23              : import { useTelemetry } from '@comfyorg/telemetry'
      24              : import { useWorkflowStore } from '@/platform/workflow/management/stores/workflowStore'
      25              : import LinearRunErrorWarning from '@/renderer/extensions/linearMode/LinearRunErrorWarning.vue'
      26              : import { LINEAR_RUN_ERROR_WARNING_DESCRIPTION_ID } from '@/renderer/extensions/linearMode/linearRunErrorWarningIds'
      27              : import PartnerNodesList from '@/renderer/extensions/linearMode/PartnerNodesList.vue'
      28              : import { useCommandStore } from '@/platform/keybindings/commandStore'
      29              : import { useQueueSettingsStore } from '@/stores/queueSettingsStore'
      30              : import { useAppMode } from '@/composables/useAppMode'
      31              : import { useAppModeStore } from '@/stores/appModeStore'
      32              : import { useExecutionErrorStore } from '@/stores/executionErrorStore'
      33              : import { useMissingMediaStore } from '@/platform/workflowErrors/missingMedia/missingMediaStore'
      34              : import { useTemplateInputDownloadStore } from '@/platform/workflow/templates/stores/templateInputDownloadStore'
      35              : 
      36           72 : const { t } = useI18n()
      37           72 : const commandStore = useCommandStore()
      38           72 : const { batchCount } = storeToRefs(useQueueSettingsStore())
      39           72 : const settingStore = useSettingStore()
      40           72 : const { canRunWorkflows, showsSubscribeToRunPrompt } = useBillingContext()
      41           72 : const showsCloudSubscribePrompt = computed(
      42              :   () => isCloud && showsSubscribeToRunPrompt.value
      43              : )
      44           72 : const workflowStore = useWorkflowStore()
      45           72 : const { isBuilderMode } = useAppMode()
      46           72 : const appModeStore = useAppModeStore()
      47           72 : const { hasOutputs } = storeToRefs(appModeStore)
      48           72 : const { hasAnyError, hasMissingError } = storeToRefs(useExecutionErrorStore())
      49           72 : const missingMediaStore = useMissingMediaStore()
      50           72 : const templateInputDownloadStore = useTemplateInputDownloadStore()
      51           72 : const { overlayMessage } = useErrorOverlayState()
      52              : 
      53              : const { toastTo, mobile } = defineProps<{
      54              :   toastTo?: string | HTMLElement
      55              :   mobile?: boolean
      56              : }>()
      57              : defineEmits<{ navigateOutputs: [] }>()
      58           72 : defineExpose({ runButtonClick, handleDragDrop })
      59              : 
      60              : //NOTE: due to batching, will never be greater than 2
      61           72 : const pendingJobQueues = ref(0)
      62           72 : const { ready: jobToastTimeout, start: resetJobToastTimeout } = useTimeout(
      63              :   8000,
      64              :   { controls: true, immediate: false }
      65              : )
      66           72 : const widgetListRef = useTemplateRef('widgetListRef')
      67         2355 : const linearRunButtonTestId = 'linear-run-button'
      68         2355 : const linearInputDownloadStatusId = 'linear-input-download-status'
      69           72 : const requiredInputDownloads = computed(() => {
      70           73 :   const requiredFilenames = new Set(
      71              :     (missingMediaStore.missingMediaCandidates ?? []).map(({ name }) => name)
      72              :   )
      73           73 :   return templateInputDownloadStore.downloads.filter(({ filename }) =>
      74              :     requiredFilenames.has(filename)
      75              :   )
      76              : })
      77           72 : const isPreparingInputDownloads = computed(
      78              :   () => requiredInputDownloads.value.length > 0
      79              : )
      80           72 : const isFinalizingInputDownloads = computed(() =>
      81              :   requiredInputDownloads.value.every(({ status }) => status === 'completed')
      82              : )
      83           72 : const inputDownloadProgress = computed(() => {
      84            0 :   const progress = requiredInputDownloads.value.map(
      85              :     (download) => download.progress
      86              :   )
      87            0 :   if (!progress.length || progress.some((value) => value === null)) return null
      88            0 :   return Math.round(
      89              :     (progress.reduce<number>((sum, value) => sum + (value ?? 0), 0) /
      90              :       progress.length) *
      91              :       100
      92              :   )
      93              : })
      94           72 : const inputDownloadLabel = computed(() =>
      95              :   isFinalizingInputDownloads.value
      96              :     ? t('linearMode.inputDownloads.finalizing')
      97              :     : t(
      98              :         'linearMode.inputDownloads.downloading',
      99              :         { count: requiredInputDownloads.value.length },
     100              :         requiredInputDownloads.value.length
     101              :       )
     102              : )
     103           72 : const runButtonIconClass = computed(() =>
     104              :   isPreparingInputDownloads.value
     105              :     ? 'icon-[lucide--loader-circle] animate-spin'
     106              :     : hasMissingError.value
     107              :       ? 'icon-[lucide--triangle-alert]'
     108              :       : 'icon-[lucide--play]'
     109              : )
     110           72 : const showRunErrorWarning = computed(
     111              :   () =>
     112              :     hasAnyError.value &&
     113              :     toValue(canRunWorkflows) &&
     114              :     toValue(overlayMessage).trim().length > 0
     115              : )
     116              : 
     117              : //TODO: refactor out of this file.
     118              : //code length is small, but changes should propagate
     119            4 : async function runButtonClick(e: Event) {
     120            4 :   try {
     121            4 :     pendingJobQueues.value += 1
     122            4 :     resetJobToastTimeout()
     123              :     const isShiftPressed = 'shiftKey' in e && e.shiftKey
     124            4 :     const commandId = isShiftPressed
     125              :       ? 'Comfy.QueuePromptFront'
     126              :       : 'Comfy.QueuePrompt'
     127              : 
     128            4 :     if (batchCount.value > 1) {
     129            0 :       useTelemetry()?.trackUiButtonClicked({
     130              :         button_id: 'queue_run_multiple_batches_submitted',
     131              :         element_group: 'app_mode'
     132              :       })
     133              :     }
     134            4 :     await commandStore.execute(commandId, {
     135              :       metadata: {
     136              :         subscribe_to_run: false,
     137              :         trigger_source: 'linear'
     138              :       }
     139              :     })
     140              :   } finally {
     141              :     //TODO: Error state indicator for failed queue?
     142            3 :     pendingJobQueues.value -= 1
     143              :   }
     144              : }
     145            3 : function handleDragDrop() {
     146            3 :   return widgetListRef.value?.handleDragDrop()
     147              : }
     148              : 
     149            3 : function replayAppModeTour() {
     150            3 :   useOnboardingTourStore().replayTour('appMode')
     151              : }
     152           72 : </script>
     153              : <template>
     154              :   <div
     155          160 :     v-if="!isBuilderMode && hasOutputs"
     156              :     class="flex h-full min-w-80 flex-col"
     157              :     v-bind="$attrs"
     158              :   >
     159              :     <section
     160              :       v-if="!mobile"
     161              :       data-testid="linear-workflow-info"
     162              :       class="flex h-12 items-center gap-2 border-x border-border/50 bg-background px-4 py-2 contain-size"
     163              :     >
     164              :       <span
     165              :         class="min-w-0 flex-1 truncate font-bold"
     166              :         v-text="workflowStore.activeWorkflow?.filename"
     167              :       />
     168              :       <Button
     169              :         :tooltip="t('onboardingCoachmarks.appMode.replay')"
     170              :         tooltip-side="bottom"
     171              :         variant="muted-textonly"
     172              :         size="icon"
     173              :         :aria-label="t('onboardingCoachmarks.appMode.replay')"
     174              :         class="border border-solid hover:border-border hover:text-foreground"
     175              :         @click="replayAppModeTour"
     176              :       >
     177              :         <i class="icon-[lucide--circle-question-mark]" />
     178              :       </Button>
     179              :     </section>
     180              :     <div
     181              :       class="flex h-full flex-col gap-2 border-x bg-background px-2 md:border-y"
     182              :     >
     183              :       <section
     184              :         v-coachmark="COACH_IDS.inputsList"
     185              :         data-testid="linear-widgets"
     186              :         class="grow scroll-shadows-background overflow-y-auto contain-size"
     187              :       >
     188              :         <AppModeWidgetList ref="widgetListRef" :mobile />
     189              :       </section>
     190              :       <Teleport
     191              :         v-if="!jobToastTimeout || pendingJobQueues > 0"
     192              :         defer
     193              :         :disabled="mobile"
     194              :         :to="toastTo"
     195              :       >
     196              :         <div
     197              :           class="flex h-10 items-center gap-2 rounded-lg bg-foreground p-1 pr-2 text-background md:h-8 md:bg-secondary md:text-foreground"
     198              :         >
     199              :           <template v-if="pendingJobQueues === 0">
     200              :             <i class="icon-[lucide--check] size-5 not-md:bg-success" />
     201              :             <span class="mr-auto" v-text="t('queue.jobAddedToQueue')" />
     202              :             <Button
     203              :               v-if="mobile"
     204              :               variant="inverted"
     205              :               @click="$emit('navigateOutputs')"
     206              :             >
     207              :               {{ t('linearMode.viewJob') }}
     208              :             </Button>
     209              :           </template>
     210              :           <template v-else>
     211              :             <Loader size="sm" />
     212              :             <span v-text="t('queue.jobQueueing')" />
     213              :           </template>
     214              :         </div>
     215              :       </Teleport>
     216              :       <section
     217              :         v-if="isPreparingInputDownloads"
     218              :         :id="linearInputDownloadStatusId"
     219              :         role="status"
     220              :         data-testid="linear-input-download-status"
     221              :         class="mx-2 flex flex-col gap-2 rounded-lg border bg-background p-3 text-sm"
     222              :       >
     223              :         <div class="flex items-center gap-2">
     224              :           <Loader size="sm" />
     225              :           <span class="min-w-0 flex-1" v-text="inputDownloadLabel" />
     226              :           <span
     227              :             v-if="inputDownloadProgress !== null"
     228              :             class="text-muted-foreground tabular-nums"
     229              :             v-text="`${inputDownloadProgress}%`"
     230              :           />
     231              :         </div>
     232              :         <span
     233              :           role="progressbar"
     234              :           :aria-label="inputDownloadLabel"
     235              :           aria-valuemin="0"
     236              :           aria-valuemax="100"
     237              :           :aria-valuenow="inputDownloadProgress ?? undefined"
     238              :           class="block h-1 overflow-hidden rounded-full bg-secondary"
     239              :         >
     240              :           <span
     241              :             :class="
     242              :               cn(
     243              :                 'block h-full rounded-full bg-primary transition-[width]',
     244              :                 inputDownloadProgress === null && 'w-1/3 animate-pulse'
     245              :               )
     246              :             "
     247              :             :style="
     248              :               inputDownloadProgress === null
     249              :                 ? undefined
     250              :                 : { width: `${inputDownloadProgress}%` }
     251              :             "
     252              :           />
     253              :         </span>
     254              :       </section>
     255              :       <PartnerNodesList v-if="!mobile" />
     256              :       <section
     257              :         v-if="mobile"
     258              :         :data-testid="linearRunButtonTestId"
     259              :         class="border-t p-4 pb-6"
     260              :       >
     261              :         <LinearRunErrorWarning v-if="showRunErrorWarning" />
     262              :         <div v-coachmark="COACH_IDS.appRunButton">
     263              :           <SubscribeToRunButton
     264              :             v-if="showsCloudSubscribePrompt"
     265              :             class="mt-4 w-full"
     266              :           />
     267              :           <div v-else class="mt-4 flex">
     268              :             <PartnerNodesList mobile />
     269              :             <PopoverRoot>
     270              :               <PopoverTrigger as-child>
     271              :                 <Button size="lg" class="-mr-3 pr-7">
     272              :                   <i
     273              :                     v-if="batchCount == 1"
     274              :                     class="icon-[lucide--chevron-down]"
     275              :                   />
     276              :                   <div v-else class="tabular-nums" v-text="`${batchCount}x`" />
     277              :                 </Button>
     278              :               </PopoverTrigger>
     279              :               <PopoverContent
     280              :                 side="top"
     281              :                 :side-offset="5"
     282              :                 dismiss-on-viewport-change
     283              :                 class="w-auto overflow-visible rounded-lg border-border/50 p-2 shadow-sm"
     284              :                 @open-auto-focus.prevent
     285              :               >
     286              :                 <div
     287              :                   class="m-1 mb-2 text-muted-foreground"
     288              :                   v-text="t('linearMode.runCount')"
     289              :                 />
     290              :                 <ScrubableNumberInput
     291              :                   v-model="batchCount"
     292              :                   :aria-label="t('linearMode.runCount')"
     293              :                   :min="1"
     294              :                   :max="settingStore.get('Comfy.QueueButton.BatchCountLimit')"
     295              :                   class="h-10 min-w-40"
     296              :                 />
     297              :                 <PopoverArrow class="fill-background stroke-border/50" />
     298              :               </PopoverContent>
     299              :             </PopoverRoot>
     300              :             <Button
     301              :               variant="inverted"
     302              :               class="grow"
     303              :               size="lg"
     304              :               :aria-describedby="
     305              :                 isPreparingInputDownloads
     306              :                   ? linearInputDownloadStatusId
     307              :                   : showRunErrorWarning
     308              :                     ? LINEAR_RUN_ERROR_WARNING_DESCRIPTION_ID
     309              :                     : undefined
     310              :               "
     311              :               :disabled="isPreparingInputDownloads"
     312              :               @click="runButtonClick"
     313              :             >
     314              :               <i
     315              :                 aria-hidden="true"
     316              :                 :class="runButtonIconClass"
     317              :                 data-testid="linear-run-button-icon"
     318              :               />
     319              :               {{ t('menu.run') }}
     320              :             </Button>
     321              :           </div>
     322              :         </div>
     323              :       </section>
     324              :       <section
     325              :         v-else
     326              :         :data-testid="linearRunButtonTestId"
     327              :         class="border-t p-4 pb-6"
     328              :       >
     329              :         <LinearRunErrorWarning v-if="showRunErrorWarning" />
     330              :         <div v-coachmark="COACH_IDS.appRunButton">
     331              :           <div
     332              :             class="m-1 mb-2 text-muted-foreground"
     333              :             v-text="t('linearMode.runCount')"
     334              :           />
     335              :           <ScrubableNumberInput
     336              :             v-model="batchCount"
     337              :             :aria-label="t('linearMode.runCount')"
     338              :             :min="1"
     339              :             :max="settingStore.get('Comfy.QueueButton.BatchCountLimit')"
     340              :             class="h-7 min-w-40"
     341              :           />
     342              :           <SubscribeToRunButton
     343              :             v-if="showsCloudSubscribePrompt"
     344              :             class="mt-4 w-full"
     345              :           />
     346              :           <Button
     347              :             v-else
     348              :             variant="inverted"
     349              :             class="mt-4 w-full"
     350              :             size="lg"
     351              :             :aria-describedby="
     352              :               isPreparingInputDownloads
     353              :                 ? linearInputDownloadStatusId
     354              :                 : showRunErrorWarning
     355              :                   ? LINEAR_RUN_ERROR_WARNING_DESCRIPTION_ID
     356              :                   : undefined
     357              :             "
     358              :             :disabled="isPreparingInputDownloads"
     359              :             @click="runButtonClick"
     360              :           >
     361              :             <i
     362              :               aria-hidden="true"
     363              :               :class="runButtonIconClass"
     364              :               data-testid="linear-run-button-icon"
     365              :             />
     366              :             {{ t('menu.run') }}
     367              :           </Button>
     368              :         </div>
     369              :         <FreeTierQuota />
     370              :       </section>
     371              :     </div>
     372              :   </div>
     373              :   <div
     374              :     v-else-if="mobile"
     375              :     class="flex size-full items-center bg-background p-4 text-center"
     376              :     v-text="t('linearMode.mobileNoWorkflow')"
     377              :   />
     378              : </template>
        

Generated by: LCOV version 2.0-1