Skip to content

Commit

Permalink
Support refresh on group node combos (comfyanonymous#2625)
Browse files Browse the repository at this point in the history
* Support refresh on group node combos

* fix check
  • Loading branch information
pythongosssss authored Jan 23, 2024
1 parent 05cd006 commit 3762e67
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
28 changes: 28 additions & 0 deletions web/extensions/core/groupNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -966,6 +966,26 @@ export class GroupNodeHandler {
api.removeEventListener("executing", executing);
api.removeEventListener("executed", executed);
};

this.node.refreshComboInNode = (defs) => {
// Update combo widget options
for (const widgetName in this.groupData.newToOldWidgetMap) {
const widget = this.node.widgets.find((w) => w.name === widgetName);
if (widget?.type === "combo") {
const old = this.groupData.newToOldWidgetMap[widgetName];
const def = defs[old.node.type];
const input = def?.input?.required?.[old.inputName] ?? def?.input?.optional?.[old.inputName];
if (!input) continue;

widget.options.values = input[0];

if (old.inputName !== "image" && !widget.options.values.includes(widget.value)) {
widget.value = widget.options.values[0];
widget.callback(widget.value);
}
}
}
};
}

updateInnerWidgets() {
Expand Down Expand Up @@ -1245,6 +1265,14 @@ const ext = {
node[GROUP] = new GroupNodeHandler(node);
}
},
async refreshComboInNodes(defs) {
// Re-register group nodes so new ones are created with the correct options
Object.assign(globalDefs, defs);
const nodes = app.graph.extra?.groupNodes;
if (nodes) {
await GroupNodeConfig.registerFromWorkflow(nodes, {});
}
}
};

app.registerExtension(ext);
2 changes: 2 additions & 0 deletions web/scripts/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2212,6 +2212,8 @@ export class ComfyApp {
}
}
}

await this.#invokeExtensionsAsync("refreshComboInNodes", defs);
}

/**
Expand Down

0 comments on commit 3762e67

Please sign in to comment.