Line data Source code
1 : <template>
2 : <div class="absolute inset-0 isolate">
3 : <canvas
4 : id="graph-canvas"
5 : ref="canvasRef"
6 : tabindex="1"
7 : class="absolute inset-0 size-full touch-none"
8 : />
9 : <TransformPane
10 : v-if="shouldRenderVueNodes && comfyApp.canvas && comfyAppReady"
11 : ref="transformPaneRef"
12 : :canvas="comfyApp.canvas"
13 : :inert="canvasStore.isPickingNodes"
14 : @wheel.capture="canvasInteractions.forwardEventToCanvas"
15 : @pointerdown.capture="forwardPointerDownPanEvent"
16 : @pointerup.capture="forwardPointerUpPanEvent"
17 : @pointermove.capture="forwardPointerMovePanEvent"
18 : @keydown.space="forwardSpaceKeyEvent"
19 : >
20 8681 : <LGraphNode
21 : v-for="nodeData in allNodes"
22 : :key="nodeData.id"
23 : :node-data
24 : :data-node-id="nodeData.id"
25 : />
26 : </TransformPane>
27 : <LinkOverlayCanvas
28 : v-if="shouldRenderVueNodes && comfyApp.canvas && comfyAppReady"
29 : :canvas="comfyApp.canvas"
30 : @ready="onLinkOverlayReady"
31 : @dispose="onLinkOverlayDispose"
32 : />
33 : <SelectionRectangle v-if="comfyAppReady" />
34 : <NodeTooltip v-if="tooltipEnabled" />
35 : <NodeSearchboxPopover ref="nodeSearchboxPopoverRef" />
36 : <NodeDragPreview />
37 : <VueNodeSwitchPopup />
38 : <template v-if="comfyAppReady">
39 : <TitleEditor />
40 : <SelectionToolbox v-if="selectionToolboxEnabled" />
41 : <NodeContextMenu />
42 : <DomWidgets v-if="!shouldRenderVueNodes" />
43 : </template>
44 : <slot name="legacy-menu" />
45 : </div>
46 : <!-- Load splitter overlay only after comfyApp is ready. -->
47 : <!-- If load immediately, the top-level splitter stateKey won't be correctly
48 : synced with the stateStorage (localStorage). -->
49 : <LiteGraphCanvasSplitterOverlay v-if="comfyAppReady">
50 : <template v-if="showUI" #workflow-tabs>
51 : <div
52 : v-if="workflowTabsPosition === 'Topbar'"
53 : data-testid="topbar-workflow-tabs"
54 : class="workflow-tabs-container pointer-events-auto relative flex h-(--workflow-tabs-height) w-full items-center border-b border-border/50 bg-background shadow-md"
55 : >
56 : <WorkflowTabs />
57 : </div>
58 : </template>
59 : <template #side-toolbar>
60 : <SideToolbar v-if="showUI && !isBuilderMode && !linearMode" />
61 : </template>
62 : <template v-if="betaMenuEnabled" #side-bar-panel>
63 : <div
64 : :inert="canvasStore.isPickingNodes"
65 : class="sidebar-content-container size-full overflow-x-hidden overflow-y-auto transition-opacity duration-200 ease-in-out"
66 : :class="{ 'opacity-0': canvasStore.isPickingNodes }"
67 : >
68 : <ExtensionSlot v-if="activeSidebarTab" :extension="activeSidebarTab" />
69 : </div>
70 : </template>
71 : <template v-if="showUI && !isBuilderMode" #topmenu>
72 : <TopMenuSection />
73 : </template>
74 : <template v-if="betaMenuEnabled" #bottom-panel>
75 : <BottomPanel />
76 : </template>
77 : <template v-if="betaMenuEnabled" #right-side-panel>
78 : <AppBuilder v-if="isBuilderMode" />
79 : <PropertiesPanel v-else />
80 : </template>
81 : <template v-if="showUI" #agent-panel="{ hasOpaqueNeighbor }">
82 : <component
83 : :is="DockedAgentPanel"
84 : v-if="agentDocked && !linearMode"
85 : :has-opaque-neighbor="hasOpaqueNeighbor"
86 : />
87 : </template>
88 : <template #graph-canvas-panel>
89 : <MiniMap
90 : v-if="
91 : comfyAppReady &&
92 : minimapEnabled &&
93 : betaMenuEnabled &&
94 : !isBuilderMode &&
95 : !canvasStore.isPickingNodes
96 : "
97 : class="pointer-events-auto"
98 : />
99 : <GraphCanvasMenu
100 : v-if="canvasMenuEnabled && !isBuilderMode"
101 : class="pointer-events-auto"
102 : />
103 : <NodeSelectionModeBanner />
104 : </template>
105 : </LiteGraphCanvasSplitterOverlay>
106 : </template>
107 :
108 : <script lang="ts">
109 2355 : let activeStartup: symbol | undefined
110 : </script>
111 :
112 : <script setup lang="ts">
113 : import { LIGHT_THEME_NODE_LIGHTNESS } from '@/renderer/extensions/vueNodes/utils/nodeStyleUtils'
114 : import { until, useEventListener } from '@vueuse/core'
115 : import {
116 : computed,
117 : nextTick,
118 : onMounted,
119 : onUnmounted,
120 : ref,
121 : shallowRef,
122 : useTemplateRef,
123 : watch,
124 : watchEffect
125 : } from 'vue'
126 : import { useI18n } from 'vue-i18n'
127 :
128 : import {
129 : isMiddleButtonEvent,
130 : isMiddleButtonHeld,
131 : isMiddlePointerInput
132 : } from '@/base/pointerUtils'
133 : import LiteGraphCanvasSplitterOverlay from '@/components/LiteGraphCanvasSplitterOverlay.vue'
134 : import TopMenuSection from '@/components/TopMenuSection.vue'
135 : import BottomPanel from '@/components/bottomPanel/BottomPanel.vue'
136 : import AppBuilder from '@/components/builder/AppBuilder.vue'
137 : import VueNodeSwitchPopup from '@/components/builder/VueNodeSwitchPopup.vue'
138 : import ExtensionSlot from '@/components/common/ExtensionSlot.vue'
139 : import DomWidgets from '@/components/graph/DomWidgets.vue'
140 : import GraphCanvasMenu from '@/components/graph/GraphCanvasMenu.vue'
141 : import { createNodeProgressCanvasSync } from '@/components/graph/nodeProgressCanvasSync'
142 : import LinkOverlayCanvas from '@/components/graph/LinkOverlayCanvas.vue'
143 : import NodeTooltip from '@/components/graph/NodeTooltip.vue'
144 : import NodeContextMenu from '@/components/graph/NodeContextMenu.vue'
145 : import NodeDragPreview from '@/components/graph/NodeDragPreview.vue'
146 : import NodeSelectionModeBanner from '@/components/graph/NodeSelectionModeBanner.vue'
147 : import SelectionToolbox from '@/components/graph/SelectionToolbox.vue'
148 : import TitleEditor from '@/components/graph/TitleEditor.vue'
149 : import PropertiesPanel from '@/renderer/extensions/propertiesPanel/PropertiesPanel.vue'
150 : import { useAgentDockMount } from '@/workbench/extensions/agent/composables/useAgentDockMount'
151 : import NodeSearchboxPopover from '@/components/searchbox/NodeSearchBoxPopover.vue'
152 : import SideToolbar from '@/components/sidebar/SideToolbar.vue'
153 : import WorkflowTabs from '@/components/topbar/WorkflowTabs.vue'
154 : import { useGroupContextMenu } from '@/composables/graph/useGroupContextMenu'
155 : import { installErrorClearingHooks } from '@/composables/graph/useErrorClearingHooks'
156 : import type { NodeState } from '@comfyorg/graph-model/nodeState'
157 : import { useNodeBadge } from '@/composables/node/useNodeBadge'
158 : import { useNodeEmphasis } from '@/systems/nodeEmphasisSystem'
159 : import { useTextPreviewSystem } from '@/systems/textPreviewSystem'
160 : import { useCanvasDrop } from '@/composables/useCanvasDrop'
161 : import { useContextMenuTranslation } from '@/composables/useContextMenuTranslation'
162 : import { useCopy } from '@/composables/useCopy'
163 : import { useGlobalLitegraph } from '@/composables/useGlobalLitegraph'
164 : import { usePaste } from '@/composables/usePaste'
165 : import { useVueFeatureFlags } from '@/composables/useVueFeatureFlags'
166 : import type { LGraph } from '@/lib/litegraph/src/litegraph'
167 : import { LiteGraph } from '@/lib/litegraph/src/litegraph'
168 : import { useLitegraphSettings } from '@/platform/settings/composables/useLitegraphSettings'
169 : import { CORE_SETTINGS } from '@/platform/settings/constants/coreSettings'
170 : import { useSettingStore } from '@/platform/settings/settingStore'
171 : import { isCloud } from '@/platform/distribution/types'
172 : import { waitForDeploymentPick } from '@/platform/workspace/composables/waitForDeploymentPick'
173 : import { bootstrapTracer } from '@/platform/telemetry/perf/bootstrapTracer'
174 : import { useToast } from '@/components/ui/toast/toastStore'
175 : import { useWorkflowService } from '@/platform/workflow/core/services/workflowService'
176 : import { useWorkflowStore } from '@/platform/workflow/management/stores/workflowStore'
177 : import { useWorkflowAutoSave } from '@/platform/workflow/persistence/composables/useWorkflowAutoSave'
178 : import { useWorkflowPersistenceV2 as useWorkflowPersistence } from '@/platform/workflow/persistence/composables/useWorkflowPersistenceV2'
179 : import { useNodeDataStore } from '@/stores/nodeDataStore'
180 : import { useCanvasStore } from '@/renderer/core/canvas/canvasStore'
181 : import { useCanvasInteractions } from '@/renderer/core/canvas/useCanvasInteractions'
182 : import { arrangeForLegacyRender } from '@/renderer/core/canvas/litegraph/arrangeForLegacyRender'
183 : import { notifyLayoutChanges } from '@/renderer/core/canvas/litegraph/notifyLayoutChanges'
184 : import { layoutStore } from '@/renderer/core/layout/store/layoutStore'
185 : import TransformPane from '@/renderer/core/layout/transform/TransformPane.vue'
186 : import type { StartupOutcome } from '@/platform/workflow/persistence/base/draftTypes'
187 : import { useFirstRunEntry } from '@/renderer/extensions/firstRunTour/gettingStarted/firstRunEntry'
188 : import MiniMap from '@/renderer/extensions/minimap/MiniMap.vue'
189 : import LGraphNode from '@/renderer/extensions/vueNodes/components/LGraphNode.vue'
190 : import { UnauthorizedError } from '@comfyorg/api-client/ComfyApi'
191 : import { app as comfyApp } from '@/scripts/app'
192 : import { ChangeTracker } from '@/scripts/changeTracker'
193 : import { IS_CONTROL_WIDGET } from '@/core/graph/widgets/controlWidgetMarker'
194 : import { updateControlWidgetLabel } from '@/core/graph/widgets/valueControlWidgets'
195 : import { loadExtensions } from '@/platform/extensions/services/extensionLoader'
196 : import { useThemeService } from '@/platform/theme/themeService'
197 : import { useNewUserService } from '@/services/useNewUserService'
198 : import {
199 : collapseOutsideSelectionOnPrimaryPointerDown,
200 : shouldIgnoreCopyPaste
201 : } from '@/workbench/eventHelpers'
202 : import { storeToRefs } from 'pinia'
203 :
204 : import { useBootstrapStore } from '@/stores/bootstrapStore'
205 : import { useCommandStore } from '@/platform/keybindings/commandStore'
206 : import { useExecutionStore } from '@/stores/executionStore'
207 : import { useExecutionErrorStore } from '@/stores/executionErrorStore'
208 : import { useNodeDefStore } from '@/stores/nodeDefStore'
209 : import { useThemeStore } from '@/platform/theme/themeStore'
210 : import { useSearchBoxStore } from '@/stores/workspace/searchBoxStore'
211 : import { useSubgraphStore } from '@/stores/subgraphStore'
212 : import { useAppMode } from '@/composables/useAppMode'
213 : import { useWorkspaceStore } from '@/stores/workspaceStore'
214 : import { forEachNode } from '@/utils/graphTraversalUtil'
215 :
216 : import SelectionRectangle from './SelectionRectangle.vue'
217 : import { useUrlActionLoaders } from '@/composables/useUrlActionLoaders'
218 :
219 2355 : const { t } = useI18n()
220 2355 : const emit = defineEmits<{
221 : ready: []
222 : }>()
223 2355 : const canvasRef = ref<HTMLCanvasElement | null>(null)
224 2355 : const transformPaneRef =
225 : useTemplateRef<InstanceType<typeof TransformPane>>('transformPaneRef')
226 2355 : const vueNodeDropTarget = computed(() => {
227 3214 : const element: unknown = transformPaneRef.value?.$el
228 3214 : return element instanceof HTMLElement ? element : null
229 : })
230 2355 : const nodeSearchboxPopoverRef = shallowRef<InstanceType<
231 : typeof NodeSearchboxPopover
232 : > | null>(null)
233 2355 : const settingStore = useSettingStore()
234 : // Extensions still listen for `<id>.change` events on the legacy dialog.
235 2355 : settingStore.onSettingChanged(({ id, value, oldValue }) =>
236 : comfyApp.ui.settings.dispatchChange(id, value, oldValue)
237 : )
238 2355 : const nodeDefStore = useNodeDefStore()
239 2355 : const workspaceStore = useWorkspaceStore()
240 2355 : const { isBuilderMode } = useAppMode()
241 2355 : const canvasStore = useCanvasStore()
242 2355 : const workflowStore = useWorkflowStore()
243 2355 : const nodeProgressCanvasSync = createNodeProgressCanvasSync(
244 : workflowStore.nodeToNodeLocatorId
245 : )
246 2355 : const { linearMode } = storeToRefs(canvasStore)
247 2355 : const { docked: agentDocked, DockedAgentPanel } = useAgentDockMount()
248 2355 : const executionStore = useExecutionStore()
249 2355 : const executionErrorStore = useExecutionErrorStore()
250 2355 : const toast = useToast()
251 2355 : const themeStore = useThemeStore()
252 2355 : const themeService = useThemeService()
253 2355 : const canvasInteractions = useCanvasInteractions()
254 2355 : const bootstrapStore = useBootstrapStore()
255 2355 : const { isI18nReady, i18nError } = storeToRefs(bootstrapStore)
256 2355 : const { isReady: isSettingsReady, error: settingsError } =
257 : storeToRefs(settingStore)
258 :
259 2355 : const betaMenuEnabled = computed(
260 : () => settingStore.get('Comfy.UseNewMenu') !== 'Disabled'
261 : )
262 2355 : const workflowTabsPosition = computed(() =>
263 : settingStore.get('Comfy.Workflow.WorkflowTabsPosition')
264 : )
265 2355 : const canvasMenuEnabled = computed(() =>
266 : settingStore.get('Comfy.Graph.CanvasMenu')
267 : )
268 2355 : const tooltipEnabled = computed(() => settingStore.get('Comfy.EnableTooltips'))
269 2355 : const selectionToolboxEnabled = computed(
270 : () =>
271 : settingStore.get('Comfy.Canvas.SelectionToolbox') &&
272 : !canvasStore.isPickingNodes
273 : )
274 2355 : const activeSidebarTab = computed(() => {
275 287 : return workspaceStore.sidebarTab.activeSidebarTab
276 : })
277 2355 : const showUI = computed(
278 : () => !workspaceStore.focusMode && betaMenuEnabled.value
279 : )
280 :
281 2355 : const minimapEnabled = computed(() => settingStore.get('Comfy.Minimap.Visible'))
282 :
283 : // Feature flags
284 2355 : const { shouldRenderVueNodes } = useVueFeatureFlags()
285 :
286 : // Error-clearing hooks run regardless of rendering mode (Vue or legacy canvas).
287 2355 : let cleanupErrorHooks: (() => void) | null = null
288 2355 : watch(
289 : () => canvasStore.currentGraph,
290 : (graph) => {
291 2569 : cleanupErrorHooks?.()
292 2569 : cleanupErrorHooks = graph ? installErrorClearingHooks(graph) : null
293 : }
294 : )
295 :
296 29 : function exitToLegacyRendering(graph: LGraph | null) {
297 29 : layoutStore.clearViewGeometry()
298 29 : if (graph) arrangeForLegacyRender(graph)
299 29 : canvasStore.canvas?.setDirty(true, true)
300 : }
301 :
302 2355 : watch(
303 : [shouldRenderVueNodes, () => canvasStore.currentGraph],
304 : ([enabled, graph], previous) => {
305 5027 : if (previous && previous[0] !== enabled) {
306 2456 : LiteGraph.vueNodesMode = enabled
307 2456 : if (graph) {
308 101 : forEachNode(graph.rootGraph, (node) => {
309 644 : for (const widget of node.widgets ?? []) {
310 1364 : widget.syncLiveVisibilityOptions?.()
311 1364 : widget.syncLiveDisabled?.()
312 : }
313 : })
314 : }
315 : }
316 :
317 5027 : if (enabled) {
318 1728 : layoutStore.clearViewGeometry()
319 3299 : } else if (previous?.[0]) {
320 29 : exitToLegacyRendering(graph)
321 : }
322 : },
323 : { immediate: true }
324 : )
325 :
326 2355 : watchEffect((onCleanup) => {
327 4710 : const canvas = canvasStore.canvas
328 4710 : if (canvas) onCleanup(notifyLayoutChanges(canvas))
329 : })
330 :
331 2355 : watch(
332 : () => canvasStore.isInSubgraph,
333 : (newValue, oldValue) => {
334 197 : if (oldValue && !newValue) {
335 73 : useWorkflowStore().updateActiveGraph()
336 : }
337 : }
338 : )
339 :
340 2355 : const nodeDataStore = useNodeDataStore()
341 2355 : const allNodes = computed((): NodeState[] => {
342 4162 : const { rootGraphId } = canvasStore
343 4162 : const graphId = canvasStore.currentGraph?.id
344 4162 : if (!rootGraphId || graphId === undefined) return []
345 4162 : return nodeDataStore.getGraphNodesFor(rootGraphId, graphId)
346 : })
347 830 : function onLinkOverlayReady(el: HTMLCanvasElement) {
348 830 : if (!canvasStore.canvas) return
349 830 : canvasStore.canvas.overlayCanvas = el
350 830 : canvasStore.canvas.overlayCtx = el.getContext('2d')
351 : }
352 :
353 29 : function onLinkOverlayDispose() {
354 29 : if (!canvasStore.canvas) return
355 29 : canvasStore.canvas.overlayCanvas = null
356 29 : canvasStore.canvas.overlayCtx = null
357 : }
358 :
359 2355 : watchEffect(() => {
360 4712 : LiteGraph.nodeOpacity = settingStore.get('Comfy.Node.Opacity')
361 : })
362 2355 : watchEffect(() => {
363 2373 : LiteGraph.nodeLightness =
364 : themeStore.colorScheme === 'light' ? LIGHT_THEME_NODE_LIGHTNESS : undefined
365 : })
366 :
367 2355 : watchEffect(() => {
368 4710 : nodeDefStore.showDeprecated = settingStore.get('Comfy.Node.ShowDeprecated')
369 : })
370 :
371 2355 : watchEffect(() => {
372 4710 : nodeDefStore.showExperimental = settingStore.get(
373 : 'Comfy.Node.ShowExperimental'
374 : )
375 : })
376 :
377 2355 : watchEffect(() => {
378 4710 : const spellcheckEnabled = settingStore.get('Comfy.TextareaWidget.Spellcheck')
379 : const textareas = document.querySelectorAll<HTMLTextAreaElement>(
380 : 'textarea.comfy-multiline-input'
381 : )
382 :
383 4710 : textareas.forEach((textarea: HTMLTextAreaElement) => {
384 0 : textarea.spellcheck = spellcheckEnabled
385 : // Force recheck to ensure visual update
386 0 : textarea.focus()
387 0 : textarea.blur()
388 : })
389 : })
390 :
391 2355 : watch(
392 : () => settingStore.get('Comfy.WidgetControlMode'),
393 : () => {
394 2355 : if (!canvasStore.canvas) return
395 :
396 0 : const rootGraph = comfyApp.rootGraphOrUndefined
397 0 : if (!rootGraph) return
398 :
399 0 : forEachNode(rootGraph, (n) => {
400 0 : if (!n.widgets) return
401 0 : for (const w of n.widgets) {
402 0 : if (!w[IS_CONTROL_WIDGET]) continue
403 0 : updateControlWidgetLabel(w)
404 0 : if (!w.linkedWidgets) continue
405 0 : for (const l of w.linkedWidgets) {
406 0 : updateControlWidgetLabel(l)
407 : }
408 : }
409 : })
410 0 : canvasStore.canvas.setDirty(true)
411 : }
412 : )
413 :
414 2355 : watch(
415 : [() => canvasStore.canvas, () => settingStore.get('Comfy.ColorPalette')],
416 : async ([canvas, currentPaletteId]) => {
417 4720 : if (!canvas) return
418 :
419 2374 : await themeService.setActiveTheme(currentPaletteId)
420 : }
421 : )
422 :
423 2355 : watch(
424 : () => settingStore.get('Comfy.Canvas.BackgroundImage'),
425 : async () => {
426 2364 : if (!canvasStore.canvas) return
427 9 : const currentPaletteId = themeStore.activePresetId
428 455 : if (!currentPaletteId) return
429 :
430 : // Reload color palette to apply background image
431 9 : await themeService.setActiveTheme(currentPaletteId)
432 : // Mark background canvas as dirty
433 9 : canvasStore.canvas.setDirty(false, true)
434 : }
435 : )
436 2355 : watch(
437 : () => themeStore.activePresetId,
438 : async (newValue) => {
439 26 : await settingStore.set('Comfy.ColorPalette', newValue)
440 : }
441 : )
442 :
443 : /**
444 : * Propagates execution progress from the store to LiteGraph node objects
445 : * and triggers a canvas redraw.
446 : *
447 : * No `deep: true` needed — `nodeLocationProgressStates` is a computed that
448 : * returns a new `Record` object on every progress event (the underlying
449 : * `nodeProgressStates` ref is replaced wholesale by the WebSocket handler).
450 : *
451 : * `currentGraph` triggers this watcher on subgraph navigation so stale
452 : * progress bars are cleared when returning to the root graph.
453 : */
454 2355 : watch(
455 : () =>
456 : [
457 : executionStore.nodeLocationProgressStates,
458 : canvasStore.canvas,
459 : canvasStore.currentGraph
460 : ] as const,
461 : ([nodeLocationProgressStates, canvas]) => {
462 6542 : nodeProgressCanvasSync.sync(
463 : nodeLocationProgressStates,
464 : canvas,
465 : canvas?.graph ?? canvasStore.currentGraph
466 : )
467 : }
468 : )
469 :
470 2355 : onUnmounted(nodeProgressCanvasSync.dispose)
471 :
472 : // Repaint canvas when node errors change.
473 : // Slot error flags are reconciled by reconcileNodeErrorFlags in executionErrorStore.
474 2355 : watch(
475 : () => executionErrorStore.lastNodeErrors,
476 : () => {
477 38 : comfyApp.canvas?.setDirty(true, true)
478 : }
479 : )
480 :
481 2355 : watch(
482 : () => canvasStore.selectedNodeIds,
483 : () => canvasStore.canvas?.setDirty(true, true)
484 : )
485 :
486 2355 : useEventListener(
487 : canvasRef,
488 : 'litegraph:no-items-selected',
489 : () => {
490 0 : toast.warning(t('toastMessages.nothingSelected'), { duration: 2000 })
491 : },
492 : { passive: true }
493 : )
494 :
495 2355 : const comfyAppReady = ref(false)
496 2355 : const workflowPersistence = useWorkflowPersistence()
497 2355 : const { runUrlActionLoaders } = useUrlActionLoaders()
498 2355 : useCanvasDrop(canvasRef)
499 2355 : useCanvasDrop(vueNodeDropTarget)
500 2355 : useLitegraphSettings()
501 2355 : useNodeBadge()
502 2355 : useNodeEmphasis()
503 2355 : useTextPreviewSystem()
504 :
505 2355 : useGlobalLitegraph()
506 2355 : useContextMenuTranslation()
507 2355 : useGroupContextMenu()
508 2355 : useCopy()
509 2355 : usePaste()
510 2355 : useWorkflowAutoSave()
511 :
512 : // Start watching for locale change after the initial value is loaded.
513 2355 : watch(
514 : () => settingStore.get('Comfy.Locale'),
515 : async (_newLocale, oldLocale) => {
516 2354 : if (!oldLocale) return
517 7 : await Promise.all([
518 : until(() => isSettingsReady.value || !!settingsError.value).toBe(true),
519 : until(() => isI18nReady.value || !!i18nError.value).toBe(true)
520 : ])
521 2354 : if (settingsError.value || i18nError.value) {
522 0 : console.warn(
523 : 'Somehow the Locale setting was changed while the settings or i18n had a setup error'
524 : )
525 : }
526 7 : await useCommandStore().execute('Comfy.RefreshNodeDefinitions')
527 7 : await useWorkflowService().reloadCurrentWorkflow()
528 : }
529 : )
530 2355 : useEventListener(
531 : () => canvasStore.canvas?.canvas,
532 : 'litegraph:set-graph',
533 : () => {
534 216 : workflowStore.updateActiveGraph()
535 : }
536 : )
537 :
538 2355 : let disposed = false
539 2355 : const lateCustomNodeWork = new AbortController()
540 2355 : const startupOwner = Symbol()
541 :
542 2355 : function finishStartup(outcome: 'completed' | 'failed') {
543 2355 : if (activeStartup !== startupOwner) return
544 2355 : activeStartup = undefined
545 2355 : workspaceStore.spinner = false
546 2355 : bootstrapTracer.complete(outcome)
547 : }
548 :
549 : function showDeploymentLookupToast() {
550 : toast.error(t('deploymentSwitcher.lookupUnavailable'), {
551 : description: t('deploymentSwitcher.lookupUnavailableDetail'),
552 : action: {
553 : label: t('deploymentSwitcher.reload'),
554 : onClick: () => window.location.reload()
555 : }
556 : })
557 : }
558 :
559 2355 : onMounted(async () => {
560 2355 : activeStartup = startupOwner
561 2355 : bootstrapTracer.resumeWatchdog()
562 2355 : comfyApp.vueAppReady = true
563 2355 : workspaceStore.spinner = true
564 2355 : let startupOutcome: StartupOutcome | undefined
565 2355 : let urlTemplateId: string | undefined
566 2355 : let bootstrapOutcome: 'completed' | 'failed' = 'failed'
567 2355 : try {
568 2355 : ChangeTracker.init()
569 :
570 2355 : await until(() => isSettingsReady.value || !!settingsError.value).toBe(true)
571 :
572 2355 : if (settingsError.value) {
573 0 : if (settingsError.value instanceof UnauthorizedError) {
574 0 : localStorage.removeItem('Comfy.userId')
575 0 : localStorage.removeItem('Comfy.userName')
576 0 : window.location.reload()
577 0 : return
578 : }
579 0 : throw settingsError.value
580 : }
581 :
582 2355 : CORE_SETTINGS.forEach(settingStore.addSetting)
583 :
584 2355 : await Promise.all([
585 : until(() => isI18nReady.value || !!i18nError.value).toBe(true),
586 : bootstrapTracer.settle('bootstrap/new-user', () =>
587 : useNewUserService().initializeIfNewUser()
588 : )
589 : ])
590 2355 : if (i18nError.value) {
591 0 : console.warn(
592 : '[GraphCanvas] Failed to load custom nodes i18n:',
593 : i18nError.value
594 : )
595 : }
596 :
597 2355 : await bootstrapTracer.settle('bootstrap/extensions-load', () =>
598 : loadExtensions(lateCustomNodeWork.signal)
599 : )
600 :
601 2355 : const canvas = canvasRef.value
602 2355 : if (!canvas) throw new TypeError('GraphCanvas mounted without a canvas')
603 : const deploymentConfirmed =
604 : !isCloud ||
605 : (await bootstrapTracer.settle('bootstrap/deployment-pick', () =>
606 : waitForDeploymentPick(showDeploymentLookupToast)
607 : ))
608 2355 : if (disposed) return
609 : if (!deploymentConfirmed) showDeploymentLookupToast()
610 2355 : await comfyApp.setup(canvas)
611 2355 : await themeService.loadCustomThemePresets()
612 2355 : if (disposed) return
613 2355 : canvasStore.canvas = comfyApp.canvas
614 2355 : canvasStore.canvas.render_canvas_border = false
615 2355 : useSearchBoxStore().setPopoverRef(nodeSearchboxPopoverRef.value)
616 :
617 2355 : window.app = comfyApp
618 2355 : window.graph = comfyApp.graph
619 :
620 2355 : comfyAppReady.value = true
621 :
622 2355 : if (comfyApp.canvas?.graph) {
623 2355 : cleanupErrorHooks = installErrorClearingHooks(comfyApp.canvas.graph)
624 : }
625 :
626 2355 : await bootstrapTracer.settle('bootstrap/workflow-restore', async () => {
627 2355 : startupOutcome = await workflowPersistence.initializeWorkflow()
628 2355 : await workflowPersistence.restoreWorkflowTabsState()
629 2355 : urlTemplateId = await workflowPersistence.loadTemplateFromUrlIfPresent()
630 2355 : if (!workflowStore.activeWorkflow)
631 1 : await useWorkflowService().loadDefaultWorkflow()
632 2355 : await useFirstRunEntry().handleStartupOutcome(startupOutcome)
633 : })
634 2355 : bootstrapOutcome = 'completed'
635 : } finally {
636 2355 : if (!disposed) {
637 2355 : workflowStore.markTabsRestored()
638 2355 : finishStartup(bootstrapOutcome)
639 : }
640 : }
641 2355 : const sharedStatus =
642 : await workflowPersistence.loadSharedWorkflowFromUrlIfPresent()
643 :
644 2353 : await runUrlActionLoaders()
645 :
646 2353 : const { useReleaseStore } =
647 : await import('@/platform/updates/common/releaseStore')
648 : const releaseStore = useReleaseStore()
649 2335 : void releaseStore.initialize()
650 :
651 2335 : emit('ready')
652 :
653 2335 : void useSubgraphStore().fetchSubgraphs()
654 :
655 2335 : await nextTick()
656 2335 : try {
657 2335 : await useFirstRunEntry().handleUrlWorkflow(
658 : startupOutcome,
659 : urlTemplateId,
660 : sharedStatus
661 : )
662 : } catch (error) {
663 0 : console.error('[GraphCanvas] Failed to offer the first-run tour:', error)
664 : }
665 : })
666 :
667 2355 : onUnmounted(() => {
668 0 : disposed = true
669 0 : lateCustomNodeWork.abort()
670 0 : void nextTick(() => {
671 0 : if (activeStartup !== startupOwner) return
672 0 : activeStartup = undefined
673 0 : workspaceStore.spinner = false
674 0 : bootstrapTracer.suspendWatchdog()
675 : })
676 0 : cleanupErrorHooks?.()
677 0 : cleanupErrorHooks = null
678 : })
679 :
680 2355 : useEventListener(
681 : canvasRef,
682 : 'pointerdown',
683 : collapseOutsideSelectionOnPrimaryPointerDown,
684 : { capture: true }
685 : )
686 :
687 1060 : function forwardPointerDownPanEvent(e: PointerEvent) {
688 1060 : collapseOutsideSelectionOnPrimaryPointerDown(e)
689 1060 : forwardPanEvent(e, isMiddlePointerInput)
690 : }
691 :
692 1963 : function forwardPointerMovePanEvent(e: PointerEvent) {
693 1963 : forwardPanEvent(e, isMiddleButtonHeld)
694 : }
695 :
696 1045 : function forwardPointerUpPanEvent(e: PointerEvent) {
697 1045 : forwardPanEvent(e, isMiddleButtonEvent)
698 : }
699 :
700 4 : function forwardSpaceKeyEvent(e: KeyboardEvent) {
701 4 : const target = e.target
702 4 : if (
703 : !layoutStore.isDraggingVueNodes.value ||
704 : target instanceof HTMLInputElement ||
705 : target instanceof HTMLTextAreaElement ||
706 : target instanceof HTMLSelectElement ||
707 : target instanceof HTMLButtonElement ||
708 : (target instanceof HTMLElement && target.isContentEditable)
709 : )
710 2 : return
711 :
712 4 : comfyApp.canvas?.processKey(e)
713 : }
714 :
715 4068 : function forwardPanEvent(
716 : e: PointerEvent,
717 : isMiddleInput: (event: PointerEvent) => boolean
718 : ) {
719 4068 : if (!isMiddleInput(e)) return
720 4068 : if (shouldIgnoreCopyPaste(e.target) && document.activeElement === e.target)
721 0 : return
722 :
723 2 : canvasInteractions.forwardEventToCanvas(e)
724 : }
725 : </script>
|