LCOV - code coverage report
Current view: top level - src/platform/settings/composables - useLitegraphSettings.ts Coverage Total Hit
Test: ComfyUI E2E Coverage Lines: 100.0 % 79 79
Test Date: 2026-11-17 04:17:53

            Line data    Source code
       1              : import { watch, watchEffect } from 'vue'
       2              : 
       3              : import { clearLinkSelection } from '@/lib/litegraph/src/canvas/linkSelection'
       4              : import {
       5              :   CanvasPointer,
       6              :   LGraphNode,
       7              :   LiteGraph
       8              : } from '@/lib/litegraph/src/litegraph'
       9              : import { LinkRenderType } from '@comfyorg/graph-model/globalEnums'
      10              : import { useSettingStore } from '@/platform/settings/settingStore'
      11              : // oxlint-disable-next-line comfy/no-restricted-paths
      12              : import { useCanvasStore } from '@/renderer/core/canvas/canvasStore'
      13              : 
      14              : /**
      15              :  * Watch for changes in the setting store and update the LiteGraph settings accordingly.
      16              :  */
      17         2355 : export const useLitegraphSettings = () => {
      18         2355 :   const settingStore = useSettingStore()
      19         2355 :   const canvasStore = useCanvasStore()
      20              : 
      21         2355 :   watch(
      22              :     [
      23              :       () => settingStore.get('Comfy.Graph.CanvasInfo'),
      24              :       () => canvasStore.canvas,
      25              :       () => canvasStore.isPickingNodes
      26              :     ],
      27              :     ([canvasInfoEnabled, canvas, picking]) => {
      28         4713 :       if (canvas) {
      29         2356 :         canvas.show_info = canvasInfoEnabled && !picking
      30         2356 :         canvas.draw(false, true)
      31              :       }
      32              :     },
      33              :     { immediate: true }
      34              :   )
      35              : 
      36         2355 :   watchEffect(() => {
      37         7062 :     const zoomSpeed = settingStore.get('Comfy.Graph.ZoomSpeed')
      38         7062 :     if (canvasStore.canvas) {
      39         2355 :       canvasStore.canvas.zoom_speed = zoomSpeed
      40              :     }
      41              :   })
      42              : 
      43         2355 :   watchEffect(() => {
      44         7067 :     const autoPanSpeed = settingStore.get('Comfy.Graph.AutoPanSpeed')
      45         7067 :     if (canvasStore.canvas) {
      46         2357 :       canvasStore.canvas.auto_pan_speed = autoPanSpeed
      47              :     }
      48              :   })
      49              : 
      50         2355 :   watchEffect(() => {
      51         4710 :     LiteGraph.snaps_for_comfy = settingStore.get(
      52              :       'Comfy.Node.AutoSnapLinkToSlot'
      53              :     )
      54              :   })
      55              : 
      56         2355 :   watchEffect(() => {
      57         4710 :     LiteGraph.snap_highlights_node = settingStore.get(
      58              :       'Comfy.Node.SnapHighlightsNode'
      59              :     )
      60              :   })
      61              : 
      62         2355 :   watchEffect(() => {
      63         4711 :     LGraphNode.keepAllLinksOnBypass = settingStore.get(
      64              :       'Comfy.Node.BypassAllLinksOnDelete'
      65              :     )
      66              :   })
      67              : 
      68         2355 :   watchEffect(() => {
      69         4711 :     LiteGraph.middle_click_slot_add_default_node = settingStore.get(
      70              :       'Comfy.Node.MiddleClickRerouteNode'
      71              :     )
      72              :   })
      73              : 
      74         2355 :   watch(
      75              :     [() => settingStore.get('Comfy.LinkRenderMode'), () => canvasStore.canvas],
      76              :     ([linkRenderMode, canvas]) => {
      77         7067 :       if (canvas) {
      78         2357 :         canvas.links_render_mode = linkRenderMode
      79         2357 :         if (linkRenderMode === LinkRenderType.HIDDEN_LINK)
      80            1 :           clearLinkSelection(canvas)
      81         2357 :         canvas.setDirty(false, true)
      82              :       }
      83              :     },
      84              :     { immediate: true }
      85              :   )
      86              : 
      87         2355 :   watch(
      88              :     [
      89              :       () => settingStore.get('LiteGraph.Canvas.MinFontSizeForLOD'),
      90              :       () => canvasStore.canvas
      91              :     ],
      92              :     ([minFontSizeForLOD, canvas]) => {
      93         7068 :       if (canvas) {
      94         2358 :         canvas.min_font_size_for_lod = minFontSizeForLOD
      95         2358 :         canvas.setDirty(true, true)
      96              :       }
      97              :     },
      98              :     { immediate: true }
      99              :   )
     100              : 
     101         2355 :   watch(
     102              :     [
     103              :       () => settingStore.get('Comfy.Graph.LinkMarkers'),
     104              :       () => canvasStore.canvas
     105              :     ],
     106              :     ([linkMarkerShape, canvas]) => {
     107         7065 :       if (canvas) {
     108         2355 :         canvas.linkMarkerShape = linkMarkerShape
     109         2355 :         canvas.setDirty(false, true)
     110              :       }
     111              :     },
     112              :     { immediate: true }
     113              :   )
     114              : 
     115         2355 :   watchEffect(() => {
     116         7068 :     const maximumFps = settingStore.get('LiteGraph.Canvas.MaximumFps')
     117         7068 :     const { canvas } = canvasStore
     118         7068 :     if (canvas) canvas.maximumFps = maximumFps
     119              :   })
     120              : 
     121         2355 :   watchEffect(() => {
     122         7066 :     const dragZoomEnabled = settingStore.get('Comfy.Graph.CtrlShiftZoom')
     123         7066 :     const { canvas } = canvasStore
     124         7066 :     if (canvas) canvas.dragZoomEnabled = dragZoomEnabled
     125              :   })
     126              : 
     127         2355 :   watchEffect(() => {
     128         7044 :     const liveSelection = settingStore.get('Comfy.Graph.LiveSelection')
     129         7044 :     const { canvas } = canvasStore
     130         7044 :     if (canvas) canvas.liveSelection = liveSelection
     131              :   })
     132              : 
     133         2355 :   watchEffect(() => {
     134         4713 :     CanvasPointer.doubleClickTime = settingStore.get(
     135              :       'Comfy.Pointer.DoubleClickTime'
     136              :     )
     137              :   })
     138              : 
     139         2355 :   watchEffect(() => {
     140         4703 :     CanvasPointer.maxClickDrift = settingStore.get('Comfy.Pointer.ClickDrift')
     141              :   })
     142              : 
     143         2355 :   watchEffect(() => {
     144         2359 :     LiteGraph.CANVAS_GRID_SIZE = settingStore.get('Comfy.SnapToGrid.GridSize')
     145              :   })
     146              : 
     147         2355 :   watchEffect(() => {
     148         4710 :     LiteGraph.alwaysSnapToGrid = settingStore.get('pysssss.SnapToGrid')
     149              :   })
     150              : 
     151         2355 :   watchEffect(() => {
     152         4711 :     LiteGraph.context_menu_scaling = settingStore.get(
     153              :       'LiteGraph.ContextMenu.Scaling'
     154              :     )
     155              :   })
     156              : 
     157         2355 :   watchEffect(() => {
     158         4706 :     LiteGraph.Reroute.maxSplineOffset = settingStore.get(
     159              :       'LiteGraph.Reroute.SplineOffset'
     160              :     )
     161              :   })
     162              : 
     163         2355 :   watchEffect(() => {
     164         4684 :     const navigationMode = settingStore.get('Comfy.Canvas.NavigationMode') as
     165              :       | 'standard'
     166              :       | 'legacy'
     167              :       | 'custom'
     168              : 
     169         4684 :     LiteGraph.canvasNavigationMode = navigationMode
     170         4684 :     LiteGraph.macTrackpadGestures = navigationMode === 'standard'
     171              :   })
     172              : 
     173         2355 :   watchEffect(() => {
     174         4677 :     const leftMouseBehavior = settingStore.get(
     175              :       'Comfy.Canvas.LeftMouseClickBehavior'
     176              :     ) as 'panning' | 'select'
     177         4677 :     LiteGraph.leftMouseClickBehavior = leftMouseBehavior
     178              :   })
     179              : 
     180         2355 :   watchEffect(() => {
     181         4677 :     const mouseWheelScroll = settingStore.get(
     182              :       'Comfy.Canvas.MouseWheelScroll'
     183              :     ) as 'panning' | 'zoom'
     184         4677 :     LiteGraph.mouseWheelScroll = mouseWheelScroll
     185              :   })
     186              : 
     187         2355 :   watchEffect(() => {
     188         4711 :     LiteGraph.saveViewportWithGraph = settingStore.get(
     189              :       'Comfy.EnableWorkflowViewRestore'
     190              :     )
     191              :   })
     192         2355 :   watchEffect(() => {
     193         4708 :     LiteGraph.namedValuesRestore = settingStore.get(
     194              :       'Comfy.Workflow.NamedValuesRestore'
     195              :     )
     196              :   })
     197              : 
     198         2355 :   watchEffect(() => {
     199         7056 :     const selectChildren = settingStore.get(
     200              :       'LiteGraph.Group.SelectChildrenOnClick'
     201              :     )
     202         7056 :     if (canvasStore.canvas)
     203         2357 :       canvasStore.canvas.groupSelectChildren = selectChildren
     204              :   })
     205              : }
        

Generated by: LCOV version 2.0-1