@@ -10,6 +10,7 @@ import { ComfyWorkflow, useWorkflowStore } from '@/stores/workflowStore'
1010
1111import { api } from './api'
1212import type { ComfyApp } from './app'
13+ import { app } from './app'
1314
1415function clone < T > ( obj : T ) : T {
1516 return JSON . parse ( JSON . stringify ( obj ) )
@@ -36,11 +37,6 @@ export class ChangeTracker {
3637 ds ?: { scale : number ; offset : [ number , number ] }
3738 nodeOutputs ?: Record < string , any >
3839
39- static app ?: ComfyApp
40- get app ( ) : ComfyApp {
41- return ChangeTracker . app !
42- }
43-
4440 constructor (
4541 /**
4642 * The workflow that this change tracker is tracking
@@ -68,18 +64,18 @@ export class ChangeTracker {
6864
6965 store ( ) {
7066 this . ds = {
71- scale : this . app . canvas . ds . scale ,
72- offset : [ this . app . canvas . ds . offset [ 0 ] , this . app . canvas . ds . offset [ 1 ] ]
67+ scale : app . canvas . ds . scale ,
68+ offset : [ app . canvas . ds . offset [ 0 ] , app . canvas . ds . offset [ 1 ] ]
7369 }
7470 }
7571
7672 restore ( ) {
7773 if ( this . ds ) {
78- this . app . canvas . ds . scale = this . ds . scale
79- this . app . canvas . ds . offset = this . ds . offset
74+ app . canvas . ds . scale = this . ds . scale
75+ app . canvas . ds . offset = this . ds . offset
8076 }
8177 if ( this . nodeOutputs ) {
82- this . app . nodeOutputs = this . nodeOutputs
78+ app . nodeOutputs = this . nodeOutputs
8379 }
8480 }
8581
@@ -105,10 +101,8 @@ export class ChangeTracker {
105101 }
106102
107103 checkState ( ) {
108- if ( ! this . app . graph || this . changeCount ) return
109- // @ts -expect-error zod type issue on ComfyWorkflowJSON. ComfyWorkflowJSON
110- // is stricter than LiteGraph's serialisation schema.
111- const currentState = clone ( this . app . graph . serialize ( ) ) as ComfyWorkflowJSON
104+ if ( ! app . graph || this . changeCount ) return
105+ const currentState = clone ( app . graph . serialize ( ) ) as ComfyWorkflowJSON
112106 if ( ! this . activeState ) {
113107 this . activeState = currentState
114108 return
@@ -132,7 +126,7 @@ export class ChangeTracker {
132126 target . push ( this . activeState )
133127 this . restoringState = true
134128 try {
135- await this . app . loadGraphData ( prevState , false , false , this . workflow , {
129+ await app . loadGraphData ( prevState , false , false , this . workflow , {
136130 showMissingModelsDialog : false ,
137131 showMissingNodesDialog : false ,
138132 checkForRerouteMigration : false
@@ -189,13 +183,11 @@ export class ChangeTracker {
189183 }
190184 }
191185
192- static init ( app : ComfyApp ) {
186+ static init ( ) {
193187 const getCurrentChangeTracker = ( ) =>
194188 useWorkflowStore ( ) . activeWorkflow ?. changeTracker
195189 const checkState = ( ) => getCurrentChangeTracker ( ) ?. checkState ( )
196190
197- ChangeTracker . app = app
198-
199191 let keyIgnored = false
200192 window . addEventListener (
201193 'keydown' ,
@@ -237,7 +229,7 @@ export class ChangeTracker {
237229 if ( await changeTracker . undoRedo ( e ) ) return
238230
239231 // If our active element is some type of input then handle changes after they're done
240- if ( ChangeTracker . bindInput ( app , bindInputEl ) ) return
232+ if ( ChangeTracker . bindInput ( bindInputEl ) ) return
241233 logger . debug ( 'checkState on keydown' )
242234 changeTracker . checkState ( )
243235 } )
@@ -339,7 +331,7 @@ export class ChangeTracker {
339331 } )
340332 }
341333
342- static bindInput ( _app : ComfyApp , activeEl : Element | null ) : boolean {
334+ static bindInput ( activeEl : Element | null ) : boolean {
343335 if (
344336 ! activeEl ||
345337 activeEl . tagName === 'CANVAS' ||
0 commit comments