Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/scripts/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ import { useNodeOutputStore } from '@/stores/imagePreviewStore'
import { KeyComboImpl, useKeybindingStore } from '@/stores/keybindingStore'
import { useModelStore } from '@/stores/modelStore'
import { SYSTEM_NODE_DEFS, useNodeDefStore } from '@/stores/nodeDefStore'
import { useSubgraphNavigationStore } from '@/stores/subgraphNavigationStore'
import { useSubgraphStore } from '@/stores/subgraphStore'
import { useWidgetStore } from '@/stores/widgetStore'
import { useWorkspaceStore } from '@/stores/workspaceStore'
Expand Down Expand Up @@ -1305,6 +1306,7 @@ export class ComfyApp {
workflow,
this.graph.serialize() as unknown as ComfyWorkflowJSON
)
useSubgraphNavigationStore().updateHash()
requestAnimationFrame(() => {
this.graph.setDirtyCanvas(true, true)
})
Expand Down
58 changes: 56 additions & 2 deletions src/stores/subgraphNavigationStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { computed, ref, shallowRef, watch } from 'vue'
import type { DragAndScaleState } from '@/lib/litegraph/src/DragAndScale'
import type { Subgraph } from '@/lib/litegraph/src/litegraph'
import { useWorkflowStore } from '@/platform/workflow/management/stores/workflowStore'
import { useWorkflowService } from '@/platform/workflow/core/services/workflowService'
import { useCanvasStore } from '@/renderer/core/canvas/canvasStore'
import { app } from '@/scripts/app'
import { findSubgraphPathById } from '@/utils/graphTraversalUtil'
Expand Down Expand Up @@ -38,8 +39,6 @@ export const useSubgraphNavigationStore = defineStore(
*/
const getCurrentRootGraphId = () => {
const canvas = canvasStore.getCanvas()
if (!canvas) return 'root'

return canvas.graph?.rootGraph?.id ?? 'root'
}

Expand Down Expand Up @@ -157,6 +156,60 @@ export const useSubgraphNavigationStore = defineStore(
onNavigated(newValue, oldValue)
}
)
//Allow navigation with forward/back buttons
//TODO: Extend for dialogues?
//TODO: force update widget.promoted
function onHashChange() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about on page reload? I.e., initial load

const root = app.graph
const locatorId = window.location.hash.slice(1) ?? root.id
const canvas = canvasStore.getCanvas()
if (canvas.graph?.id === locatorId) return
const targetGraph =
(locatorId || root.id) !== root.id
? root.subgraphs.get(locatorId)
: root
if (targetGraph) return canvas.setGraph(targetGraph)

//Search all open workflows
for (const workflow of workflowStore.openWorkflows) {
const { activeState } = workflow
if (!activeState) continue
const subgraphs = activeState.definitions?.subgraphs ?? []
for (const graph of [activeState, ...subgraphs]) {
if (graph.id !== locatorId) continue
useWorkflowService()
.openWorkflow(workflow)
.then(() => {
const targetGraph =
app.graph.id === locatorId
? app.graph
: app.graph.subgraphs.get(locatorId)
if (!targetGraph) {
console.error('subgraph poofed after load?')
return
}

return canvas.setGraph(targetGraph)
})
}
}
}
//TODO: Initialize with store, replace hash if none?
let hasInitializedHandler = false
function updateHash() {
if (!hasInitializedHandler) {
hasInitializedHandler = true
window.location.hash = window.location.hash.slice(1) || app.graph.id
window.onhashchange = onHashChange
}
const newId = canvasStore.getCanvas().graph?.id ?? ''
const currentId = window.location.hash.slice(1)
if ((newId || app.graph.id) === (currentId || app.graph.id)) return
window.location.hash = newId
}
//update navigation hash
//NOTE: Doesn't apply on workflow load
watch(() => canvasStore.currentGraph, updateHash)

return {
activeSubgraph,
Expand All @@ -165,6 +218,7 @@ export const useSubgraphNavigationStore = defineStore(
exportState,
saveViewport,
restoreViewport,
updateHash,
viewportCache
}
}
Expand Down
Loading