LCOV - code coverage report
Current view: top level - src/platform/workspace - openCustomDeploymentDialog.ts Coverage Total Hit
Test: ComfyUI E2E Coverage Lines: 3.6 % 28 1
Test Date: 2026-11-17 04:17:53

            Line data    Source code
       1              : import { nextTick } from 'vue'
       2              : import type { Component } from 'vue'
       3              : 
       4              : import { useErrorHandling } from '@/composables/useErrorHandling'
       5              : import { t } from '@/i18n'
       6              : import {
       7              :   DEPLOY_VIDEO_POSTER_SRC,
       8              :   DEPLOY_VIDEO_SOURCES
       9              : } from '@/platform/workflow/deploy/constants'
      10              : import { CUSTOM_DEPLOYMENT_BRIEF } from '@/platform/workspace/customDeploymentBrief'
      11              : import { customDeploymentPitch } from '@/platform/workspace/customDeploymentPitch'
      12              : import type { CustomDeploymentPitch } from '@/platform/workspace/customDeploymentPitch'
      13              : import { useDialogStore } from '@/stores/dialogStore'
      14              : 
      15            0 : function cardOf(module: { default?: Component } | undefined): Component {
      16            0 :   if (!module?.default)
      17            0 :     throw new TypeError('Failed to fetch dynamically imported module')
      18            0 :   return module.default
      19              : }
      20              : 
      21              : /** Lazily opens a headless deployment card; a failed load shows a toast and resolves false. */
      22            0 : export async function openCardDialog(
      23              :   key: string,
      24              :   load: () => Promise<{ default?: Component } | undefined>,
      25              :   props: Record<string, unknown>,
      26              :   isStillWanted: () => boolean = () => true
      27              : ): Promise<boolean> {
      28            0 :   const card = await load()
      29              :     .then(cardOf)
      30              :     .catch((error: unknown) => {
      31            0 :       useErrorHandling().toastErrorHandler(error)
      32            0 :       return null
      33              :     })
      34            0 :   if (card === null || !isStillWanted()) return false
      35            0 :   const dialogStore = useDialogStore()
      36            0 :   const hide = () => dialogStore.closeDialog({ key })
      37            0 :   dialogStore.showDialog({
      38              :     key,
      39              :     component: card,
      40              :     props: { ...props, onDone: hide, onDismiss: hide },
      41              :     dialogComponentProps: {
      42              :       dismissOnPointerDownOutside: true,
      43              :       headless: true
      44              :     }
      45              :   })
      46            0 :   return true
      47              : }
      48              : 
      49            0 : function openCustomDeploymentDialog(
      50              :   key: string,
      51              :   pitch: CustomDeploymentPitch
      52              : ): Promise<boolean> {
      53            0 :   return openCardDialog(
      54              :     key,
      55              :     () => import('@/platform/workspace/components/CustomDeploymentCard.vue'),
      56              :     {
      57              :       pitch,
      58              :       videoSources: DEPLOY_VIDEO_SOURCES,
      59              :       posterSrc: DEPLOY_VIDEO_POSTER_SRC
      60              :     }
      61              :   )
      62              : }
      63              : 
      64              : /** Opens the Create a custom deployment dialog; false if it could not load. */
      65            0 : export function openCreateCustomDeploymentDialog(): Promise<boolean> {
      66            0 :   return openCustomDeploymentDialog(
      67              :     'global-create-custom-deployment',
      68              :     customDeploymentPitch()
      69              :   )
      70              : }
      71              : 
      72              : /** Opens the Extensions dialog on Comfy Cloud; false if it could not load. */
      73              : export function openDeployCustomNodesDialog(): Promise<boolean> {
      74              :   return openCustomDeploymentDialog('global-deploy-custom-nodes', {
      75              :     title: t('deploymentSwitcher.deployCustomNodes.title'),
      76              :     body: t('deploymentSwitcher.deployCustomNodes.body'),
      77              :     points: [
      78              :       t('deploymentSwitcher.deployCustomNodes.pointNodes'),
      79              :       t('deploymentSwitcher.customDeployment.pointGpu'),
      80              :       t('deploymentSwitcher.customDeployment.pointApi')
      81              :     ],
      82              :     platformLabel: t('deployToComfyApi.deployOnPlatform'),
      83              :     brief: CUSTOM_DEPLOYMENT_BRIEF
      84              :   })
      85              : }
      86              : 
      87         2355 : const WORKFLOW_NEEDS_DEPLOYMENT_KEY = 'global-workflow-needs-deployment'
      88              : 
      89            0 : function loadWorkflowNeedsDeploymentCard() {
      90            0 :   return import('@/platform/workspace/components/WorkflowNeedsDeploymentCard.vue')
      91              : }
      92              : 
      93              : /** Preloads the workflow deployment dialog; false if loading fails. */
      94              : export function preloadWorkflowNeedsDeploymentDialog(): Promise<boolean> {
      95              :   return loadWorkflowNeedsDeploymentCard()
      96              :     .then(cardOf)
      97              :     .then(
      98              :       () => true,
      99              :       () => false
     100              :     )
     101              : }
     102              : 
     103              : /** Whether the workflow deployment dialog is open. */
     104            0 : export function isWorkflowNeedsDeploymentDialogOpen(): boolean {
     105            0 :   return useDialogStore().isDialogOpen(WORKFLOW_NEEDS_DEPLOYMENT_KEY)
     106              : }
     107              : 
     108              : /** Opens the workflow deployment dialog, replacing an earlier one. */
     109            0 : export async function openWorkflowNeedsDeploymentDialog(): Promise<boolean> {
     110            0 :   const dialogStore = useDialogStore()
     111            0 :   if (isWorkflowNeedsDeploymentDialogOpen()) {
     112            0 :     dialogStore.closeDialog({ key: WORKFLOW_NEEDS_DEPLOYMENT_KEY })
     113            0 :     await nextTick()
     114              :   }
     115            0 :   return openCardDialog(
     116              :     WORKFLOW_NEEDS_DEPLOYMENT_KEY,
     117              :     loadWorkflowNeedsDeploymentCard,
     118              :     {}
     119              :   )
     120              : }
        

Generated by: LCOV version 2.0-1