Line data Source code
1 : import { useRunButtonTelemetry } from '@/composables/useRunButtonTelemetry'
2 : import { app as comfyApp } from '@/scripts/app'
3 : import type { ComfyApp } from '@/scripts/app'
4 : import { ComfyUI } from '@/scripts/ui'
5 : import { ComfyAppMenu } from '@/scripts/ui/menu/index'
6 : import { $el } from '@/scripts/ui/utils'
7 : import { useLitegraphService } from '@/services/litegraphService'
8 : import { useNodeOutputStore } from '@/stores/nodeOutputStore'
9 : import { useWorkspaceStore } from '@/stores/workspaceStore'
10 :
11 2356 : const detachers = new WeakMap<ComfyApp, () => void>()
12 :
13 : /**
14 : * Builds the legacy menu, dialogs, and placeholder body elements on an app,
15 : * replacing any earlier attachment. Returns a function that removes them.
16 : */
17 2355 : export function attachLegacyUI(target: ComfyApp = comfyApp): () => void {
18 2355 : detachers.get(target)?.()
19 :
20 2355 : target.ui = new ComfyUI(target, {
21 : resetView: () => useLitegraphService().resetView(),
22 : restoreOutputs: (outputs) => useNodeOutputStore().restoreOutputs(outputs),
23 : trackRunButton: (intent) => useRunButtonTelemetry().trackRunButton(intent),
24 : enterFocusMode: () => {
25 378 : useWorkspaceStore().focusMode = true
26 : }
27 : })
28 2355 : target.bodyTop = $el('div.comfyui-body-top')
29 2355 : target.bodyLeft = $el('div.comfyui-body-left')
30 2355 : target.bodyRight = $el('div.comfyui-body-right')
31 2355 : target.bodyBottom = $el('div.comfyui-body-bottom')
32 2355 : target.canvasContainer = $el('div.graph-canvas-container')
33 2355 : target.menu = new ComfyAppMenu()
34 :
35 2355 : const { ui, menu } = target
36 2355 : const detach = () => {
37 0 : if (detachers.get(target) !== detach) return
38 0 : detachers.delete(target)
39 0 : ui.dispose()
40 0 : menu.element.remove()
41 : }
42 2355 : detachers.set(target, detach)
43 2355 : return detach
44 : }
|