LCOV - code coverage report
Current view: top level - src - main.ts Coverage Total Hit
Test: ComfyUI E2E Coverage Lines: 97.0 % 66 64
Test Date: 2026-11-17 04:17:53

            Line data    Source code
       1              : import { captureMessage } from '@sentry/vue'
       2              : import { createPinia } from 'pinia'
       3              : import type { Pinia } from 'pinia'
       4              : import 'primeicons/primeicons.css'
       5              : import { createApp } from 'vue'
       6              : import type { App as VueApp } from 'vue'
       7              : 
       8              : import { setAssertReporter } from '@/base/assert'
       9              : import { flushProxyWidgetMigration } from '@/core/graph/subgraph/migration/proxyWidgetMigration'
      10              : import { autoExposeKnownPreviewNodes } from '@/core/graph/subgraph/promotionUtils'
      11              : import { LGraph } from '@/lib/litegraph/src/litegraph'
      12              : import { installCloudApiAuth } from '@/platform/auth/cloudApiAuthProvider'
      13              : import { firebaseIdentity } from '@/platform/auth/firebaseIdentity'
      14              : import {
      15              :   configValueOrDefault,
      16              :   remoteConfig
      17              : } from '@/platform/remoteConfig/remoteConfig'
      18              : import { reportAssertFailure } from '@/platform/telemetry/assertFailureReporter'
      19              : import { initSentry } from '@/platform/telemetry/initSentry'
      20              : import {
      21              :   markStoresPending,
      22              :   markStoresReady
      23              : } from '@/platform/telemetry/storeReadiness'
      24              : import { syncHostUserIdWithFirebaseAuth } from '@/platform/telemetry/hostUserIdSync'
      25              : import '@/platform/telemetry/initErrorReporter'
      26              : import { flushErrorReports } from '@comfyorg/telemetry/reportError'
      27              : import { bootstrapTracer } from '@/platform/telemetry/perf/bootstrapTracer'
      28              : import '@/lib/litegraph/public/css/litegraph.css'
      29              : import { createAppRouter } from '@/router'
      30              : import { captureSafeExtensionBoot } from '@/platform/customNodes/safeExtensionBoot'
      31              : import { isDesktop, isNightly } from '@/platform/distribution/types'
      32              : import { stripPaymentReturnParams } from '@/platform/billing/subscription/utils/paymentReturnUrl'
      33              : import { useToast } from '@/components/ui/toast/toastStore'
      34              : import { createToastId } from '@/types/toastId'
      35              : import { installWorkspaceApiAuth } from '@/platform/workspace/api/workspaceApiAuth'
      36              : import { api } from '@/scripts/api'
      37              : import { useBootstrapStore } from '@/stores/bootstrapStore'
      38              : import { attachLegacyUI } from '@/core/legacyUI/attachLegacyUI'
      39              : import { handleDesktopWorkflowHandoff } from '@/platform/openOnCloud/desktopWorkflowRelay'
      40              : 
      41              : import App from './App.vue'
      42              : // Intentionally relative import to ensure the CSS is loaded in the right order (after litegraph.css)
      43              : import './assets/css/style.css'
      44              : import { i18n, t } from './i18n'
      45              : 
      46         2356 : const isCloud = __DISTRIBUTION__ === 'cloud'
      47         2356 : const hasHostTelemetryBridge = Boolean(window.__comfyDesktop2?.Telemetry)
      48              : 
      49         2355 : async function loadRemoteConfigBeforeFirebase(): Promise<void> {
      50         2355 :   await bootstrapTracer.settle('startup/remote-config', async () => {
      51         2355 :     const { loadRemoteConfigUntilReady, refreshRemoteConfig } =
      52              :       await import('@/platform/remoteConfig/refreshRemoteConfig')
      53              :     if (isCloud) await loadRemoteConfigUntilReady()
      54         2355 :     else await refreshRemoteConfig({ useAuth: false })
      55              :   })
      56              : }
      57              : 
      58         2355 : async function startTelemetry(): Promise<void> {
      59              :   if (isCloud) {
      60              :     await bootstrapTracer.settle('startup/telemetry-init', async () => {
      61              :       const { initTelemetry } =
      62              :         await import('@/platform/telemetry/initTelemetry')
      63              :       await initTelemetry()
      64              :     })
      65              : 
      66              :     const { startFeatureFlagTelemetry } =
      67              :       await import('@/composables/useFeatureFlags')
      68              :     const stopFeatureFlagTelemetry = startFeatureFlagTelemetry()
      69              :     import.meta.hot?.dispose(stopFeatureFlagTelemetry)
      70              :   }
      71              : 
      72         2355 :   if (hasHostTelemetryBridge) {
      73            0 :     const { initHostTelemetry } =
      74              :       await import('@/platform/telemetry/initHostTelemetry')
      75            0 :     initHostTelemetry()
      76              :   }
      77              : }
      78              : 
      79         2355 : async function startLocalAuthSession(): Promise<boolean> {
      80              :   if (isCloud) return false
      81         2355 :   return bootstrapTracer.settle('startup/local-auth', async () => {
      82         2355 :     const desktopHostAuth = window.__comfyDesktop2?.Auth
      83         2355 :     if (desktopHostAuth) {
      84            3 :       const { startDesktopHostSession } =
      85              :         await import('@/platform/auth/desktopHost/desktopHostSession')
      86            3 :       await startDesktopHostSession(desktopHostAuth)
      87            3 :       return false
      88              :     }
      89         2352 :     const { startLocalWebSession } =
      90              :       await import('@/platform/auth/localWeb/localWebSession')
      91         2352 :     const signInNotice = createToastId()
      92              :     const started = await startLocalWebSession({
      93              :       onPopupBlocked: () =>
      94              :         useToast().error(t('auth.desktopHost.popupBlocked'), {
      95              :           id: signInNotice
      96              :         }),
      97              :       onSignInFailed: () =>
      98              :         useToast().error(t('auth.desktopHost.signInFailed'), {
      99              :           id: signInNotice
     100              :         })
     101              :     })
     102         2352 :     return started === 'sign-in-failed'
     103              :   })
     104              : }
     105              : 
     106         2355 : function showLocalSignInFailure(pinia: Pinia, failed: boolean): void {
     107         2355 :   if (failed) useToast(pinia).error(t('auth.desktopHost.signInFailed'))
     108              : }
     109              : 
     110         2355 : function startLocalBillingWebFlag(pinia: Pinia): void {
     111              :   if (isCloud) return
     112         2355 :   void import('@/platform/billing/stores/localBillingWebFlagStore').then(
     113              :     ({ useLocalBillingWebFlagStore }) => useLocalBillingWebFlagStore(pinia)
     114              :   )
     115              : }
     116              : 
     117         2355 : function initFirebaseIdentity(): void {
     118         2355 :   const phaseFirebase = bootstrapTracer.startPhase('startup/firebase-init')
     119         2355 :   try {
     120         2355 :     firebaseIdentity.initialize()
     121              :   } finally {
     122         2355 :     phaseFirebase.stop()
     123              :   }
     124              : }
     125              : 
     126         2355 : function resolveRuntimeSentryDsn(): string {
     127         2355 :   return isCloud
     128              :     ? configValueOrDefault(remoteConfig.value, 'sentry_dsn', __SENTRY_DSN__)
     129              :     : __SENTRY_DSN__
     130              : }
     131              : 
     132         2355 : function initErrorReporting(app: VueApp, pinia: Pinia): void {
     133         2355 :   const dsn = resolveRuntimeSentryDsn()
     134         2355 :   const phaseSentry = bootstrapTracer.startPhase('startup/sentry-init')
     135         2355 :   initSentry({ app, dsn, enabled: !import.meta.env.DEV && !!dsn, isCloud })
     136         2355 :   phaseSentry.stop()
     137              : 
     138         2355 :   flushErrorReports()
     139              : 
     140         2355 :   setAssertReporter(
     141              :     (message, context) => {
     142              :       if (isDesktop) {
     143              :         captureMessage(message, { level: 'warning', extra: context })
     144              :       }
     145              :       if (isCloud) {
     146              :         reportAssertFailure(message, context)
     147              :       }
     148              :       if (isNightly) {
     149              :         useToast(pinia).warning('Assertion failed', { description: message })
     150              :       }
     151              :     },
     152              :     { forwardsToRum: isCloud }
     153              :   )
     154              : }
     155              : 
     156         2355 : function installSubgraphGraphHooks(): void {
     157         2355 :   LGraph.proxyWidgetMigrationFlush = (hostNode, nodeData) =>
     158              :     flushProxyWidgetMigration({
     159              :       hostNode,
     160              :       hostWidgetValues: nodeData?.widgets_values
     161              :     })
     162              : 
     163         2355 :   LGraph.autoExposePreviewNodes = (hostNode) =>
     164              :     autoExposeKnownPreviewNodes(hostNode)
     165              : }
     166              : 
     167         2355 : async function bootstrap(): Promise<void> {
     168         2355 :   bootstrapTracer.recordSinceTimeOrigin('startup/entry-modules')
     169         2355 :   api.captureLaunchContext()
     170         2355 :   captureSafeExtensionBoot()
     171              : 
     172              :   if (isCloud) {
     173              :     stripPaymentReturnParams()
     174              :     installCloudApiAuth()
     175              :   }
     176         2355 :   installWorkspaceApiAuth()
     177              : 
     178         2355 :   bootstrapTracer.armWatchdog()
     179              : 
     180         2355 :   await loadRemoteConfigBeforeFirebase()
     181              : 
     182         2355 :   markStoresPending()
     183              : 
     184         2355 :   await startTelemetry()
     185         2355 :   const localSignInFailed = await startLocalAuthSession()
     186         2355 :   initFirebaseIdentity()
     187              : 
     188         2355 :   const pinia = createPinia()
     189         2355 :   const router = await bootstrapTracer.settle('startup/router', createAppRouter)
     190         2355 :   const app = createApp(App)
     191              : 
     192         2355 :   initErrorReporting(app, pinia)
     193              : 
     194         2355 :   app.use(router).use(pinia).use(i18n)
     195              : 
     196         2355 :   markStoresReady()
     197              : 
     198         2355 :   showLocalSignInFailure(pinia, localSignInFailed)
     199         2355 :   startLocalBillingWebFlag(pinia)
     200              : 
     201              :   if (isCloud && hasHostTelemetryBridge) {
     202              :     syncHostUserIdWithFirebaseAuth()
     203              :   }
     204              : 
     205         2355 :   installSubgraphGraphHooks()
     206              : 
     207         2355 :   void useBootstrapStore(pinia).startStoreBootstrap()
     208              : 
     209         2355 :   const detachLegacyUI = attachLegacyUI()
     210              :   import.meta.hot?.dispose(detachLegacyUI)
     211              : 
     212         2355 :   app.mount('#vue-app')
     213         2355 :   bootstrapTracer.milestone('app-mounted')
     214              : }
     215              : 
     216         2356 : if (!(await handleDesktopWorkflowHandoff())) await bootstrap()
        

Generated by: LCOV version 2.0-1