Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Comfy.Workflow.SortNodeIdOnSave setting #502

Merged
merged 4 commits into from
Aug 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
},
"dependencies": {
"@atlaskit/pragmatic-drag-and-drop": "^1.2.1",
"@comfyorg/litegraph": "^0.7.46",
"@comfyorg/litegraph": "^0.7.47",
"@primevue/themes": "^4.0.0-rc.2",
"@vitejs/plugin-vue": "^5.0.5",
"@vueuse/core": "^11.0.0",
Expand Down
10 changes: 8 additions & 2 deletions src/scripts/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1925,7 +1925,10 @@ export class ComfyApp {

// Save current workflow automatically
setInterval(() => {
const workflow = JSON.stringify(this.graph.serialize())
const sortNodes =
this.vueAppReady &&
useSettingStore().get('Comfy.Workflow.SortNodeIdOnSave')
const workflow = JSON.stringify(this.graph.serialize({ sortNodes }))
localStorage.setItem('workflow', workflow)
if (api.clientId) {
sessionStorage.setItem(`workflow:${api.clientId}`, workflow)
Expand Down Expand Up @@ -2396,7 +2399,10 @@ export class ComfyApp {
}
}

const workflow = graph.serialize()
const sortNodes =
this.vueAppReady &&
useSettingStore().get('Comfy.Workflow.SortNodeIdOnSave')
const workflow = graph.serialize({ sortNodes })
const output = {}
// Process nodes in order of execution
for (const outerNode of graph.computeExecutionOrder(false)) {
Expand Down
7 changes: 7 additions & 0 deletions src/stores/settingStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,13 @@ export const useSettingStore = defineStore('setting', {
max: 24
}
})

app.ui.settings.addSetting({
id: 'Comfy.Workflow.SortNodeIdOnSave',
name: 'Sort node IDs on save',
type: 'boolean',
defaultValue: false
})
},

set<K extends keyof Settings>(key: K, value: Settings[K]) {
Expand Down
3 changes: 2 additions & 1 deletion src/types/apiTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,8 @@ const zSettings = z.record(z.any()).and(
'Comfy.SnapToGrid.GridSize': z.number(),
'Comfy.TextareaWidget.FontSize': z.number(),
'Comfy.UseNewMenu': z.any(),
'Comfy.Validation.Workflows': z.boolean()
'Comfy.Validation.Workflows': z.boolean(),
'Comfy.Workflow.SortNodeIdOnSave': z.boolean()
})
.optional()
)
Expand Down
6 changes: 3 additions & 3 deletions tests-ui/tests/litegraph.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ describe('LGraph', () => {
const node2 = new DummyNode()
const graph = createGraph(node1, node2)

const result1 = graph.serialize()
const result1 = graph.serialize({ sortNodes: true })
expect(result1.nodes).not.toHaveLength(0)
// @ts-expect-error
// @ts-expect-error Access private property.
graph._nodes = swapNodes(graph._nodes)
const result2 = graph.serialize()
const result2 = graph.serialize({ sortNodes: true })

expect(result1).toEqual(result2)
})
Expand Down
Loading