Line data Source code
1 : <template>
2 : <div class="comfyui-body isolate grid size-full overflow-hidden">
3 : <div id="comfyui-body-top" class="comfyui-body-top z-3" />
4 : <div id="comfyui-body-bottom" class="comfyui-body-bottom z-2" />
5 : <div id="comfyui-body-left" class="comfyui-body-left z-1" />
6 : <div id="comfyui-body-right" class="comfyui-body-right z-1" />
7 : <div
8 : v-show="!linearMode"
9 : id="graph-canvas-container"
10 : class="graph-canvas-container isolate"
11 : >
12 : <GraphCanvas @ready="onGraphReady">
13 : <template #legacy-menu>
14 : <div ref="legacyMenuContainerRef" />
15 : </template>
16 : </GraphCanvas>
17 : </div>
18 : <LinearView v-if="linearMode" />
19 : <template v-if="isBuilderMode">
20 : <BuilderToolbar />
21 : <BuilderMenu />
22 : <BuilderFooterToolbar />
23 : </template>
24 : </div>
25 :
26 : <AppToaster />
27 : <ToastDock>
28 : <ModelImportProgressDialog />
29 : <AssetExportProgressDialog />
30 : <ManagerProgressToast />
31 : </ToastDock>
32 : <PartnerNodesEducationCard v-if="!isCloud" />
33 : <UnloadWindowConfirmDialog v-if="!isDesktop" />
34 : <MenuHamburger />
35 : <TourOverlay v-if="graphReady" />
36 : <FirstRunTour />
37 : </template>
38 :
39 : <script setup lang="ts">
40 : import { useEventListener, useIntervalFn } from '@vueuse/core'
41 : import { storeToRefs } from 'pinia'
42 :
43 : import {
44 : computed,
45 : nextTick,
46 : onBeforeUnmount,
47 : onMounted,
48 : ref,
49 : watch,
50 : watchEffect
51 : } from 'vue'
52 :
53 : import { runWhenGlobalIdle } from '@/base/common/async'
54 : import MenuHamburger from '@/components/MenuHamburger.vue'
55 : import UnloadWindowConfirmDialog from '@/components/dialog/UnloadWindowConfirmDialog.vue'
56 : import GraphCanvas from '@/components/graph/GraphCanvas.vue'
57 : import PartnerNodesEducationCard from '@/components/actionbar/PartnerNodesEducationCard.vue'
58 : import ToastDock from '@comfyorg/design-system/toast/ToastDock'
59 : import AppToaster from '@/components/common/AppToaster.vue'
60 : import TourOverlay from '@/platform/onboarding/TourOverlay.vue'
61 : import FirstRunTour from '@/renderer/extensions/firstRunTour/FirstRunTour.vue'
62 : import { registerCoreBottomPanelTabs } from '@/composables/bottomPanelTabs/registerCoreBottomPanelTabs'
63 : import { useProgressTextPreviews } from '@/composables/node/useProgressTextPreviews'
64 : import { registerCoreSidebarTabs } from '@/composables/sidebarTabs/registerCoreSidebarTabs'
65 : import { useBrowserTabTitle } from '@/composables/useBrowserTabTitle'
66 : import { useCoreCommands } from '@/composables/useCoreCommands'
67 : import { useQueuePolling } from '@/platform/remote/comfyui/useQueuePolling'
68 : import { useReconnectNodeDefinitionRefresh } from '@/platform/customNodes/useReconnectNodeDefinitionRefresh'
69 : import { useErrorHandling } from '@/composables/useErrorHandling'
70 : import { useReconnectQueueRefresh } from '@/composables/useReconnectQueueRefresh'
71 : import { useReconnectingNotification } from '@/composables/useReconnectingNotification'
72 : import { useProgressFavicon } from '@/composables/useProgressFavicon'
73 : import { runMissingMediaPipeline } from '@/platform/workflowErrors/missingMedia/missingMediaPipeline'
74 : import { scanAllMediaCandidates } from '@/platform/workflowErrors/missingMedia/missingMediaScan'
75 : import { startTemplateInputDownloadGraphSync } from '@/platform/workflow/templates/composables/useTemplateInputDownloadGraphSync'
76 : import { refreshDownloadedTemplateInputBindings } from '@/platform/workflow/templates/utils/refreshDownloadedTemplateInputBindings'
77 : import { SERVER_CONFIG_ITEMS } from '@/constants/serverConfig'
78 : import type { ServerConfig } from '@/constants/serverConfig'
79 : import type { ServerConfigValue } from '@comfyorg/settings-core/types'
80 : import { setActiveLocale } from '@/i18n'
81 : import AssetBrowserModal from '@/platform/assets/components/AssetBrowserModal.vue'
82 : import AssetExportProgressDialog from '@/platform/assets/components/AssetExportProgressDialog.vue'
83 : import ModelImportProgressDialog from '@/platform/assets/components/ModelImportProgressDialog.vue'
84 : import { registerAssetBrowserModalComponent } from '@/platform/assets/composables/useAssetBrowserDialog'
85 : import { useDesktopCloudNotification } from '@/platform/cloud/notification/composables/useDesktopCloudNotification'
86 : import { isCloud, isDesktop } from '@/platform/distribution/types'
87 : import SettingDialog from '@/platform/settings/components/SettingDialog.vue'
88 : import { registerSettingDialogComponent } from '@/platform/settings/composables/useSettingsDialog'
89 : import { useSettingStore } from '@/platform/settings/settingStore'
90 : import { useDeploymentCompatibility } from '@/platform/workspace/composables/useDeploymentCompatibility'
91 : import { useTelemetry } from '@comfyorg/telemetry'
92 : import { reportError } from '@comfyorg/telemetry/reportError'
93 : import { getShellLayoutSnapshot } from '@/platform/telemetry/utils/getShellLayoutSnapshot'
94 : import { usePropertiesPanelStore } from '@/renderer/extensions/propertiesPanel/propertiesPanelStore'
95 : import { getPageVisibilityMetadata } from '@/workbench/extensions/agent/utils/getPageVisibilityMetadata'
96 : import { useFrontendVersionMismatchWarning } from '@/platform/updates/common/useFrontendVersionMismatchWarning'
97 : import { useVersionCompatibilityStore } from '@/platform/updates/common/versionCompatibilityStore'
98 : import { useDeploymentPickAtBoot } from '@/platform/workspace/composables/useDeploymentPickAtBoot'
99 : import { setMissingNodesNotice } from '@/platform/workflowErrors/nodeReplacement/missingNodesNotice'
100 : import { noticeMissingNodes } from '@/platform/workspace/noticeMissingNodes'
101 : import { useCanvasStore } from '@/renderer/core/canvas/canvasStore'
102 : import type { StatusWsMessageStatus } from '@comfyorg/api-client/executionTypes'
103 : import { api } from '@/scripts/api'
104 : import { app } from '@/scripts/app'
105 : import { setupAutoQueueHandler } from '@/services/autoQueueService'
106 : import { useKeybindingService } from '@/platform/keybindings/keybindingService'
107 : import { useAppMode } from '@/composables/useAppMode'
108 : import { useCommandStore } from '@/platform/keybindings/commandStore'
109 : import { useExecutionStore } from '@/stores/executionStore'
110 : import { useAuthStore } from '@/stores/authStore'
111 : import { useAssetsStore } from '@/stores/assetsStore'
112 : import { useMenuItemStore } from '@/stores/menuItemStore'
113 : import { useModelStore } from '@/stores/modelStore'
114 : import { useNodeDefStore } from '@/stores/nodeDefStore'
115 : import { useNodeFrequencyStore } from '@/stores/nodeFrequencyStore'
116 : import {
117 : useQueuePendingTaskCountStore,
118 : useQueueStore
119 : } from '@/stores/queueStore'
120 : import { useServerConfigStore } from '@/stores/serverConfigStore'
121 : import { useTemplateInputDownloadStore } from '@/platform/workflow/templates/stores/templateInputDownloadStore'
122 : import { useMissingModelDownloadStore } from '@/platform/workflowErrors/missingModel/missingModelDownloadStore'
123 : import { useThemeStore } from '@/platform/theme/themeStore'
124 : import { useSidebarTabStore } from '@/stores/workspace/sidebarTabStore'
125 : import { electronAPI, isLocalDesktopHost } from '@/utils/envUtil'
126 : import { createUuidv4 } from '@/utils/uuid'
127 : import BuilderFooterToolbar from '@/components/builder/BuilderFooterToolbar.vue'
128 : import BuilderMenu from '@/components/builder/BuilderMenu.vue'
129 : import BuilderToolbar from '@/components/builder/BuilderToolbar.vue'
130 : import LinearView from '@/views/LinearView.vue'
131 : import ManagerProgressToast from '@/platform/customNodes/manager/components/ManagerProgressToast.vue'
132 :
133 2355 : setupAutoQueueHandler()
134 2355 : useProgressFavicon()
135 2355 : useProgressTextPreviews()
136 2355 : useBrowserTabTitle()
137 2355 : useDesktopCloudNotification()
138 : if (isCloud) {
139 : const { markFor } = useDeploymentCompatibility()
140 : onBeforeUnmount(
141 : setMissingNodesNotice(
142 : (nodeTypes) => void noticeMissingNodes(nodeTypes, markFor)
143 : )
144 : )
145 : }
146 :
147 2355 : const settingStore = useSettingStore()
148 2355 : const executionStore = useExecutionStore()
149 2355 : const themeStore = useThemeStore()
150 2355 : const queueStore = useQueueStore()
151 2355 : const assetsStore = useAssetsStore()
152 2355 : const versionCompatibilityStore = useVersionCompatibilityStore()
153 2355 : const legacyMenuContainerRef = ref<HTMLDivElement | null>(null)
154 2355 : const graphReady = ref(false)
155 2355 : const { isBuilderMode, mode, isAppMode } = useAppMode()
156 2355 : const { linearMode } = storeToRefs(useCanvasStore())
157 2355 : const templateInputDownloadStore = useTemplateInputDownloadStore()
158 2355 : const templateInputGraphSync = startTemplateInputDownloadGraphSync({
159 : getReferencedInputNames: () =>
160 : new Set(scanAllMediaCandidates(app.rootGraph).map(({ name }) => name)),
161 : refreshGraphBindings: async (completedInputNames) => {
162 0 : try {
163 0 : await app.reloadNodeDefs()
164 0 : refreshDownloadedTemplateInputBindings(
165 : app.rootGraph,
166 : scanAllMediaCandidates(app.rootGraph),
167 : new Set(completedInputNames)
168 : )
169 0 : await runMissingMediaPipeline({ rootGraph: app.rootGraph, silent: true })
170 : } finally {
171 : // The transfers finished even if rebinding them did not. Releasing them
172 : // either way keeps a failed rebind from holding the run action behind a
173 : // permanent finalizing state; the failure is reported separately.
174 0 : templateInputDownloadStore.completeGraphSync(completedInputNames)
175 : }
176 : },
177 : reportError: (error) => {
178 0 : reportError(error, {
179 : surface: 'graph',
180 : errorType: 'workflow_template_input_refresh_failed'
181 : })
182 : }
183 : })
184 2355 : const stopTemplateInputDownloadTracking = startTemplateInputDownloadTracking()
185 2355 : const stopModelDownloadTracking = startModelDownloadTracking()
186 :
187 2355 : function startModelDownloadTracking() {
188 2355 : try {
189 2355 : return useMissingModelDownloadStore().startTracking()
190 : } catch (error) {
191 0 : reportError(error, {
192 : surface: 'graph',
193 : errorType: 'workflow_model_download_tracking_failed',
194 : level: 'warning'
195 : })
196 0 : return () => undefined
197 : }
198 : }
199 :
200 2355 : function startTemplateInputDownloadTracking() {
201 2355 : try {
202 2355 : return (
203 : (isLocalDesktopHost() &&
204 : window.__comfyDesktop2?.onTemplateInputDownloadProgress?.(
205 : (progress) => {
206 0 : templateInputDownloadStore.updateProgress(progress)
207 0 : templateInputGraphSync.handleProgress(progress)
208 : }
209 : )) ||
210 : (() => undefined)
211 : )
212 : } catch (error) {
213 0 : reportError(error, {
214 : surface: 'graph',
215 : errorType: 'workflow_template_input_tracking_failed',
216 : level: 'warning'
217 : })
218 0 : return () => undefined
219 : }
220 : }
221 :
222 2355 : onBeforeUnmount(() => {
223 0 : stopModelDownloadTracking()
224 0 : stopTemplateInputDownloadTracking()
225 0 : templateInputGraphSync.dispose()
226 0 : templateInputDownloadStore.clear()
227 : })
228 :
229 2355 : watch(linearMode, (isLinear) => {
230 108 : if (isLinear) {
231 89 : useSidebarTabStore().activeSidebarTabId = null
232 : }
233 : })
234 :
235 2355 : const telemetry = useTelemetry()
236 2355 : const authStore = useAuthStore()
237 : let hasTrackedLogin = false
238 :
239 : // Learn which developer-platform deployment this page booted on (FE-2434).
240 : if (isCloud) void useDeploymentPickAtBoot()
241 :
242 2355 : watch(
243 : () => themeStore.activeTheme,
244 : (newTheme) => {
245 : if (isDesktop) {
246 : electronAPI().changeTheme({
247 : color: 'rgba(0, 0, 0, 0)',
248 : symbolColor: newTheme.controls.inputTextColor
249 : })
250 : }
251 : },
252 : { immediate: true }
253 : )
254 :
255 : /**
256 : * Reports task completion telemetry to Electron analytics when tasks
257 : * transition from running to history.
258 : *
259 : * No `deep: true` needed — `queueStore.tasks` is a computed that spreads
260 : * three `shallowRef` arrays into a new array on every change, and
261 : * `TaskItemImpl` instances are immutable (replaced, never mutated).
262 : */
263 : if (isDesktop) {
264 : watch(
265 : () => queueStore.tasks,
266 : (newTasks, oldTasks) => {
267 : const oldRunningTaskIds = new Set(
268 : oldTasks.filter((task) => task.isRunning).map((task) => task.jobId)
269 : )
270 : newTasks
271 : .filter((task) => oldRunningTaskIds.has(task.jobId) && task.isHistory)
272 : .forEach((task) => {
273 : electronAPI().Events.incrementUserProperty(
274 : `execution:${task.displayStatus.toLowerCase()}`,
275 : 1
276 : )
277 : electronAPI().Events.trackEvent('execution', {
278 : status: task.displayStatus.toLowerCase()
279 : })
280 : })
281 : }
282 : )
283 : }
284 :
285 2355 : watchEffect(() => {
286 4712 : const fontSize = settingStore.get('Comfy.TextareaWidget.FontSize')
287 4712 : document.documentElement.style.setProperty(
288 : '--comfy-textarea-font-size',
289 : `${fontSize}px`
290 : )
291 : })
292 :
293 2355 : watchEffect(() => {
294 4712 : const padding = settingStore.get('Comfy.TreeExplorer.ItemPadding')
295 4712 : document.documentElement.style.setProperty(
296 : '--tree-item-padding',
297 : `${padding}px`
298 : )
299 : })
300 :
301 2355 : watchEffect(async () => {
302 4709 : const locale = settingStore.get('Comfy.Locale')
303 4709 : if (!locale) return
304 4709 : try {
305 2362 : const resolved = await setActiveLocale(locale)
306 : // Self-heal: a stored value from an older build (e.g. 'de') would otherwise
307 : // leave the language dropdown — derived from SUPPORTED_LOCALE_OPTIONS —
308 : // showing nothing selected until the user picks one manually.
309 4709 : if (resolved !== locale) {
310 1 : await settingStore.set('Comfy.Locale', resolved)
311 : }
312 : } catch (error) {
313 0 : console.error(`Failed to switch to locale "${locale}":`, error)
314 : }
315 : })
316 :
317 2355 : const useNewMenu = computed(() => {
318 2362 : return settingStore.get('Comfy.UseNewMenu')
319 : })
320 2355 : watchEffect(() => {
321 2362 : if (useNewMenu.value === 'Disabled') {
322 383 : app.ui.menuContainer.style.setProperty('display', 'block')
323 383 : app.ui.restoreMenuPosition()
324 : } else {
325 1979 : app.ui.menuContainer.style.setProperty('display', 'none')
326 : }
327 : })
328 :
329 2355 : watchEffect(() => {
330 2359 : queueStore.maxHistoryItems = settingStore.get('Comfy.Queue.MaxHistoryItems')
331 : })
332 :
333 2355 : const coreCommands = useCoreCommands()
334 2355 : useCommandStore().registerCommands(coreCommands)
335 2355 : useMenuItemStore().registerCoreMenuCommands()
336 2355 : useKeybindingService().registerCoreKeybindings()
337 2355 : registerCoreSidebarTabs()
338 2355 : registerSettingDialogComponent(SettingDialog)
339 2355 : registerAssetBrowserModalComponent(AssetBrowserModal)
340 2355 : void registerCoreBottomPanelTabs()
341 :
342 2355 : useQueuePolling()
343 2355 : const queuePendingTaskCountStore = useQueuePendingTaskCountStore()
344 :
345 2355 : const onStatus = async (e: CustomEvent<StatusWsMessageStatus>) => {
346 2639 : queuePendingTaskCountStore.update(e)
347 2639 : await queueStore.update()
348 2616 : await assetsStore.outputAssets.loadNew()
349 : }
350 :
351 2355 : const onExecutionSuccess = async () => {
352 79 : await queueStore.update()
353 77 : await assetsStore.outputAssets.loadNew()
354 : }
355 :
356 2355 : const { onReconnecting, onReconnected } = useReconnectingNotification()
357 2355 : const refreshOnReconnect = useReconnectQueueRefresh()
358 2355 : const refreshNodeDefinitionsOnReconnect = useReconnectNodeDefinitionRefresh()
359 :
360 2355 : const handleReconnected = async () => {
361 8 : onReconnected()
362 8 : void refreshNodeDefinitionsOnReconnect()
363 8 : await refreshOnReconnect()
364 : }
365 :
366 2355 : useEventListener(api, 'status', onStatus)
367 2355 : useEventListener(api, 'execution_success', onExecutionSuccess)
368 2355 : useEventListener(api, 'reconnecting', onReconnecting)
369 2355 : useEventListener(api, 'reconnected', handleReconnected)
370 :
371 2355 : onMounted(() => {
372 2355 : executionStore.bindExecutionEvents()
373 :
374 2355 : try {
375 2355 : legacyMenuContainerRef.value?.append(app.ui.menuContainer)
376 : } catch (e) {
377 0 : console.error('Failed to init ComfyUI frontend', e)
378 : }
379 : })
380 :
381 2355 : onBeforeUnmount(() => {
382 0 : executionStore.unbindExecutionEvents()
383 : })
384 :
385 2355 : useEventListener(window, 'keydown', useKeybindingService().keybindHandler)
386 :
387 2355 : const { wrapWithErrorHandling, wrapWithErrorHandlingAsync } = useErrorHandling()
388 :
389 : // Initialize version mismatch warning in setup context
390 : // It will be triggered automatically when the store is ready
391 2355 : useFrontendVersionMismatchWarning({ immediate: true })
392 :
393 2355 : void nextTick(() => {
394 2355 : versionCompatibilityStore.initialize().catch((error) => {
395 0 : console.warn('Version compatibility check failed:', error)
396 : })
397 : })
398 :
399 2355 : const onGraphReady = () => {
400 2335 : graphReady.value = true
401 2335 : runWhenGlobalIdle(() => {
402 : // Track user login when app is ready in graph view (cloud only)
403 : if (isCloud && authStore.isAuthenticated && !hasTrackedLogin) {
404 : telemetry?.trackUserLoggedIn()
405 : hasTrackedLogin = true
406 : }
407 :
408 : // Set up page visibility tracking (cloud only)
409 : if (isCloud && telemetry) {
410 : useEventListener(document, 'visibilitychange', () => {
411 : telemetry.trackPageVisibilityChanged(
412 : getPageVisibilityMetadata(
413 : document.visibilityState as 'visible' | 'hidden'
414 : )
415 : )
416 : })
417 : }
418 :
419 : // Set up tab count tracking (cloud only)
420 : if (isCloud && telemetry) {
421 : const tabCountChannel = new BroadcastChannel('comfyui-tab-count')
422 : const activeTabs = new Map<string, number>()
423 : const currentTabId = createUuidv4()
424 :
425 : // Listen for heartbeats from other tabs
426 : tabCountChannel.onmessage = (event) => {
427 : if (
428 : event.data.type === 'heartbeat' &&
429 : event.data.tabId !== currentTabId
430 : ) {
431 : activeTabs.set(event.data.tabId, Date.now())
432 : }
433 : }
434 :
435 : // 5-minute heartbeat interval
436 : useIntervalFn(() => {
437 : const now = Date.now()
438 :
439 : // Clean up stale tabs (no heartbeat for 45 seconds)
440 : activeTabs.forEach((lastHeartbeat, tabId) => {
441 : if (now - lastHeartbeat > 45000) {
442 : activeTabs.delete(tabId)
443 : }
444 : })
445 :
446 : // Broadcast our heartbeat
447 : tabCountChannel.postMessage({
448 : type: 'heartbeat',
449 : tabId: currentTabId
450 : })
451 :
452 : // Track tab count (include current tab)
453 : const tabCount = activeTabs.size + 1
454 : telemetry.trackTabCount({ tab_count: tabCount })
455 : }, 60000 * 5)
456 :
457 : // Send initial heartbeat
458 : tabCountChannel.postMessage({ type: 'heartbeat', tabId: currentTabId })
459 : }
460 :
461 : // Shell layout snapshot, once per session (cloud only)
462 : if (isCloud && telemetry) {
463 : telemetry.trackShellLayout(
464 : getShellLayoutSnapshot({
465 : view_mode: mode.value,
466 : is_app_mode: isAppMode.value,
467 : right_side_panel_open: usePropertiesPanelStore().isOpen
468 : })
469 : )
470 : }
471 :
472 : // Setting values now available after comfyApp.setup.
473 : // Load keybindings.
474 2301 : wrapWithErrorHandling(useKeybindingService().registerUserKeybindings)()
475 :
476 : // Load server config
477 2301 : wrapWithErrorHandling(useServerConfigStore().loadServerConfig)(
478 : SERVER_CONFIG_ITEMS as ServerConfig<ServerConfigValue>[],
479 : settingStore.get('Comfy.Server.ServerConfigValues')
480 : )
481 :
482 : // Load model folders
483 2301 : void wrapWithErrorHandlingAsync(useModelStore().loadModelFolders)()
484 :
485 : // Non-blocking load of node frequencies
486 2301 : void wrapWithErrorHandlingAsync(
487 : useNodeFrequencyStore().loadNodeFrequencies
488 : )()
489 :
490 : // Node defs now available after comfyApp.setup.
491 : // Explicitly initialize nodeSearchService to avoid indexing delay when
492 : // node search is triggered
493 2301 : useNodeDefStore().nodeSearchService.searchNode('')
494 : }, 1000)
495 : }
496 : </script>
497 :
498 : <style scoped>
499 : .comfyui-body {
500 : grid-template-columns: auto 1fr auto;
501 : grid-template-rows: auto 1fr auto;
502 : }
503 :
504 : /**
505 : +------------------+------------------+------------------+
506 : | |
507 : | .comfyui-body- |
508 : | top |
509 : | (spans all cols) |
510 : | |
511 : +------------------+------------------+------------------+
512 : | | | |
513 : | .comfyui-body- | #graph-canvas | .comfyui-body- |
514 : | left | | right |
515 : | | | |
516 : | | | |
517 : +------------------+------------------+------------------+
518 : | |
519 : | .comfyui-body- |
520 : | bottom |
521 : | (spans all cols) |
522 : | |
523 : +------------------+------------------+------------------+
524 : */
525 :
526 : .comfyui-body-top {
527 : order: -5;
528 : grid-column: 1/-1;
529 : grid-row: 1;
530 : display: flex;
531 : flex-direction: column;
532 : }
533 :
534 : .comfyui-body-left {
535 : order: -4;
536 : /* Position in the first column */
537 : grid-column: 1;
538 : /* Position below the top element */
539 : grid-row: 2;
540 : display: flex;
541 : }
542 :
543 : .graph-canvas-container {
544 : width: 100%;
545 : height: 100%;
546 : order: -3;
547 : grid-column: 2;
548 : grid-row: 2;
549 : position: relative;
550 : overflow: clip;
551 : }
552 :
553 : .comfyui-body-right {
554 : order: -2;
555 : grid-column: 3;
556 : grid-row: 2;
557 : }
558 :
559 : .comfyui-body-bottom {
560 : order: 4;
561 : grid-column: 1/-1;
562 : grid-row: 3;
563 : display: flex;
564 : flex-direction: column;
565 : }
566 : </style>
|