From 1b4d0b27505f018ddcaae4b64393fe54e2efdb5f Mon Sep 17 00:00:00 2001 From: tritant Date: Tue, 23 Sep 2025 15:40:00 +0200 Subject: [PATCH] Add files via upload --- js/orchestratortoogle.js | 97 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 js/orchestratortoogle.js diff --git a/js/orchestratortoogle.js b/js/orchestratortoogle.js new file mode 100644 index 0000000..9092385 --- /dev/null +++ b/js/orchestratortoogle.js @@ -0,0 +1,97 @@ +import { app } from "/scripts/app.js"; + +function updateNodeStates(selectedWorkflow, workflowTags) { + const changesToApply = []; + for (const targetNode of app.graph.nodes) { + if (targetNode.type === "OrchestratorNodeMuter") continue; + const title = targetNode.title || ""; + let isTaggedNode = false; + for (const tag of workflowTags) { + if (title.startsWith(`[[${tag}]]`)) { + isTaggedNode = true; + break; + } + } + if (isTaggedNode) { + const newMode = title.startsWith(`[[${selectedWorkflow}]]`) ? 0 : 4; + if (targetNode.mode !== newMode) { + changesToApply.push({ node: targetNode, mode: newMode }); + } + } + } + if (changesToApply.length > 0) { + for (const change of changesToApply) { + change.node.mode = change.mode; + } + app.graph.setDirtyCanvas(true, true); + } +} + +app.registerExtension({ + name: "Comfy.OrchestratorNodeMuter.AutoDiscovery", + + beforeRegisterNodeDef(nodeType, nodeData, app) { + if (nodeData.name === "OrchestratorNodeMuter") { + const onNodeCreated = nodeType.prototype.onNodeCreated; + nodeType.prototype.onNodeCreated = function () { + onNodeCreated?.apply(this, arguments); + + if (!this.widgets) { + this.widgets = []; + } + + const discoverAndBuildUI = () => { + // On nettoie les anciens widgets (tous sauf le premier s'il est permanent) + if(this.widgets?.length > 0) { + this.widgets.length = 0; + } + + const discoveredTags = new Set(); + const regex = /\[\[(.*?)\]\]/g; + + for (const node of app.graph.nodes) { + if (node.title) { + const matches = node.title.match(regex); + if (matches) { + matches.forEach(match => { + const tag = match.substring(2, match.length - 2); + discoveredTags.add(tag); + }); + } + } + } + + const WORKFLOW_TAGS = Array.from(discoveredTags); + if (WORKFLOW_TAGS.length === 0) return; + + this.widgets.push({ name: "top_spacer", type: "CUSTOM_SPACER", draw: () => {}, computeSize: () => [0, 25] }); + + const handleToggleClick = (toggledWidgetName, isTurningOn) => { + if (!isTurningOn) { + const thisWidget = this.widgets.find(w => w.name === toggledWidgetName); + if (thisWidget) thisWidget.value = true; + return; + } + for (const w of this.widgets) { + if (WORKFLOW_TAGS.includes(w.name) && w.name !== toggledWidgetName) { w.value = false; } + } + setTimeout(() => { updateNodeStates(toggledWidgetName, WORKFLOW_TAGS); }, 0); + }; + + for (const tag of WORKFLOW_TAGS) { + this.addWidget("toggle", tag, false, (value) => { handleToggleClick(tag, value); }); + } + + const firstWidget = this.widgets.find(w => w.name === WORKFLOW_TAGS[0]); + if (firstWidget) { + firstWidget.value = true; + setTimeout(() => { updateNodeStates(firstWidget.name, WORKFLOW_TAGS); }, 200); + } + }; + + // On lance le scan au chargement du nœud. + discoverAndBuildUI(); + }; + } + }, +}); \ No newline at end of file