[Refactor] Move workflow restore from app to GraphCanvas (#2349)

This commit is contained in:
Chenlei Hu
2025-01-25 15:36:50 -05:00
committed by GitHub
parent 44321e4692
commit 38b8a68e50
2 changed files with 53 additions and 39 deletions

View File

@@ -1037,44 +1037,6 @@ export class ComfyApp {
await useExtensionService().invokeExtensionsAsync('init')
await this.registerNodes()
// Load previous workflow
let restored = false
try {
const loadWorkflow = async (json) => {
if (json) {
const workflow = JSON.parse(json)
const workflowName = getStorageValue('Comfy.PreviousWorkflow')
await this.loadGraphData(workflow, true, true, workflowName)
return true
}
}
const clientId = api.initialClientId ?? api.clientId
restored =
(clientId &&
(await loadWorkflow(
sessionStorage.getItem(`workflow:${clientId}`)
))) ||
(await loadWorkflow(localStorage.getItem('workflow')))
} catch (err) {
console.error('Error loading previous workflow', err)
}
// We failed to restore a workflow so load the default
if (!restored) {
const settingStore = useSettingStore()
// If tutorial is not completed, load the tutorial workflow
if (!settingStore.get('Comfy.TutorialCompleted')) {
await settingStore.set('Comfy.TutorialCompleted', true)
// Load model folders to ensure the missing models' corresponding folders
// can be correctly identified.
await useModelStore().loadModelFolders()
await useWorkflowService().loadTutorialWorkflow()
} else {
await this.loadGraphData()
}
}
this.#addDrawNodeHandler()
this.#addDrawGroupsHandler()
this.#addDropHandler()