Skip to content

Commit

Permalink
Store shallowRef of litegraph canvas (#722)
Browse files Browse the repository at this point in the history
* Store shallowRef of litegraph canvas

* nit
  • Loading branch information
huchenlei authored Sep 3, 2024
1 parent b49b19c commit 974a7ef
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 32 deletions.
52 changes: 23 additions & 29 deletions src/components/graph/GraphCanvas.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,46 +36,42 @@ import {
} from '@comfyorg/litegraph'
import type { RenderedTreeExplorerNode } from '@/types/treeExplorerTypes'
import { useNodeBookmarkStore } from '@/stores/nodeBookmarkStore'
import { useCanvasStore } from '@/stores/graphStore'
const emit = defineEmits(['ready'])
const canvasRef = ref<HTMLCanvasElement | null>(null)
const settingStore = useSettingStore()
const nodeDefStore = useNodeDefStore()
const workspaceStore = useWorkspaceStore()
const canvasStore = useCanvasStore()
const betaMenuEnabled = computed(
() => settingStore.get('Comfy.UseNewMenu') !== 'Disabled'
)
const nodeSearchEnabled = computed<boolean>(
() => settingStore.get('Comfy.NodeSearchBoxImpl') === 'default'
)
watch(
nodeSearchEnabled,
(newVal) => {
LiteGraph.release_link_on_empty_shows_menu = !newVal
if (comfyApp.canvas) comfyApp.canvas.allow_searchbox = !newVal
},
{ immediate: true }
)
const canvasInfoEnabled = computed<boolean>(() =>
settingStore.get('Comfy.Graph.CanvasInfo')
)
watch(
canvasInfoEnabled,
(newVal) => {
if (comfyApp.canvas) comfyApp.canvas.show_info = newVal
},
{ immediate: true }
)
const zoomSpeed = computed(() => settingStore.get('Comfy.Graph.ZoomSpeed'))
watch(
zoomSpeed,
(newVal: number) => {
if (comfyApp.canvas) comfyApp.canvas['zoom_speed'] = newVal
},
{ immediate: true }
)
watchEffect(() => {
LiteGraph.release_link_on_empty_shows_menu = !nodeSearchEnabled.value
if (canvasStore.canvas) {
canvasStore.canvas.allow_searchbox = !nodeSearchEnabled.value
}
})
watchEffect(() => {
const canvasInfoEnabled = settingStore.get('Comfy.Graph.CanvasInfo')
if (canvasStore.canvas) {
canvasStore.canvas.show_info = canvasInfoEnabled
}
})
watchEffect(() => {
const zoomSpeed = settingStore.get('Comfy.Graph.ZoomSpeed')
if (canvasStore.canvas) {
canvasStore.canvas.zoom_speed = zoomSpeed
}
})
watchEffect(() => {
nodeDefStore.showDeprecated = settingStore.get('Comfy.Node.ShowDeprecated')
Expand Down Expand Up @@ -117,9 +113,7 @@ onMounted(async () => {
workspaceStore.spinner = true
await comfyApp.setup(canvasRef.value)
comfyApp.canvas.allow_searchbox = !nodeSearchEnabled.value
comfyApp.canvas.show_info = canvasInfoEnabled.value
comfyApp.canvas['zoom_speed'] = zoomSpeed.value
canvasStore.canvas = comfyApp.canvas
workspaceStore.spinner = false
window['app'] = comfyApp
Expand Down
14 changes: 11 additions & 3 deletions src/stores/graphStore.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
import { LGraphNode, LGraphGroup } from '@comfyorg/litegraph'
import { LGraphNode, LGraphGroup, LGraphCanvas } from '@comfyorg/litegraph'
import { defineStore } from 'pinia'
import { ref } from 'vue'
import { shallowRef } from 'vue'

export const useTitleEditorStore = defineStore('titleEditor', () => {
const titleEditorTarget = ref<LGraphNode | LGraphGroup | null>(null)
const titleEditorTarget = shallowRef<LGraphNode | LGraphGroup | null>(null)

return {
titleEditorTarget
}
})

export const useCanvasStore = defineStore('canvas', () => {
const canvas = shallowRef<LGraphCanvas | null>(null)

return {
canvas
}
})

0 comments on commit 974a7ef

Please sign in to comment.